I am trying to do simple shell as an exercise to myself. I am writing a function that should find an executable in the PATH, and return a pointer to a string, that contains the full path to executable. Here is what I have so far;
/*bunch of includes here*/
/*
* Find executable in path, return NULL
* if can't find.
*/
char *find_executable(char *command)
{
const char *PATH = getenv("PATH");
DIR *dp;
/* get each pathname, and try to find executable in there. */
}
int main(int argc,char *argv[])
{ /* nothing intersting here ...*/
}
I was wondering how should I separate each part of the path, and process these parts in a for loop.
say paths would be separated by ;
You can use strtok function to generate splitted token.
e.g.
char *str = "/foo/a1/b1;/bar/a1/b1"Now you can use strtok function as