Using C, I\'m trying to concatenate the filenames in a directory with their paths so that I can call stat() for each, but when I try to do using strcat inside the loop it co
The problem is that the line
char* fullpath = strcat(path, ep->d_name);
keeps appending the name of the current file to path
. Try creating a new string for the full path each time, like
char* fullpath = calloc(strlen(path) + strlen(ep->d_name) + 1);
strcat(fullpath, path);
strcat(fullpath, ep->d_name);
/* .. */
free(fullpath);