I have seen in many programs, almost only on linux, that when you run the program with a graphical manager(Clicking the executable) the program runs in a graphical window and when you run it from the terminal it runs on text mode. I want to know how to do that. Does anyone know how?
It is operating system specific.
if (getenv("DISPLAY")) startmyGUIapplication(); else if (isatty(STDIN_FILENO)) startmyterminalapplication(); else error(); // application started outside, e.g. from `crontab`