Thanks cas.
I did try using snprintf, but I'm not able to get the glob command to work with my string created with snprintf. My output is:
# ./globprog /home/myuser
1: This is argv[0] = ./globprog
2: This is argv[1] = /home/myuser
3: PATH = /home/myuser
This is the fullpath: "/home/myuser*.c"
Glob error. globresult = 16384
My code is below:
Code:
int main(int argc, char *argv[])
{
glob_t paths;
int globresult;
char fullpath[MAX_LEN+1],
**p;
printf("1: This is argv[0] = %s\n", argv[0]);
printf("2: This is argv[1] = %s\n", argv[1]);
printf("3: PATH = %s\n", argv[1]);
snprintf(fullpath, MAX_LEN, "\"%s/*.c\"", argv[1]);
printf("This is the fullpath: %s\n", fullpath);
/* Find all ".c" files in specified directory and store in paths structure*/
globresult = glob(fullpath, 0, NULL, &paths);