The more expansive solution is based on this - you need to add a bit of detail
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
int main ( int argc, char *argv[] ) {
char *env, *path, *p;
char cwd[PATH_MAX];
// if argv[0] doesn't begin with D:
// then it's probably relative to either PATH or CWD
printf( "%s\n", argv[0] );
env = getenv("PATH");
if ( env != NULL ) {
// copy the string, because we're going to use strtok
path = malloc( strlen(env) + 1 );
strcpy( path, env );
// append argv[0] onto each p, and see if the file exists
for ( p = strtok(path,";");
p != NULL;
p = strtok(NULL,";") ) {
printf( "Path=%s\n", p );
}
free( path );
}
// still not found, try current dir
getcwd( cwd, sizeof(cwd) );
printf( "CWD=%s\n", cwd );
return 0;
}