I am using
char* command = "/bin/ls";
command = "/usr/bin/gedit";
You can get the PATH variable from the environment. Then you parse it to get each component, then check in the location of each component whether the given command (file) exists there.
This is basically what the
which command does. Source code of linux utilities can be found on-line