Linux C - how to open a pdf file with default reader

sorry if i repost this...

hi.. i want to ask how to open pdf files using C in Linux

in Windows, i just use this code:
ShellExecute(GetDesktopWindow(), "open", "D:\\Folder\\File.pdf", NULL, NULL, SW_SHOWNORMAL);

thanks for advance...

there's no such thing as default readers in unix.
some desktop environments may support it.

there's no registry in unix.

Good Evening,

One possibility is given below (errors checking is left to the readers...)

#include <stdlib.h>
#include <string.h>

const char* pdf_reader="evince "; /* put the name of your pdf reader here */

void
read_pdf(const char* name)
{
   char cmd[128];

   strcpy(cmd, pdf_reader);
   strncat(cmd, name, sizeof(cmd));
   system(cmd);
}

Cheers,
Lo�c

I know Gnome has a utility program, gnome-open, which will take the file you pass to it and open that with the default application, whatever that is - presumably there's something similar for KDE and other popular desktop environments?

If you want it to be fairly portable, you could:

1) Check for the presence of, e.g. gnome-open with system("gnome-open --version"), and so on for other programs until you find one,

2) If that doesn't work, go down a similar list of raw pdf viewers (system("evince --version"), etc), and

3) If you still can't find one, prompt the user for the name of a program.

Apart from that, I don't think there's a lot else you can do.