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
You shouldn't modify argv[i]. Even if you do, you only have one argv[1], so doing strcat() on it is going to keep appending to whatever you had in it earlier.
You have another subtle bug. A directory name and file names in it should be separated by the path separator, / on most systems. You don't add that in your code.
To fix this, outside of your while loop:
size_t arglen = strlen(argv[1]);
You should do this in your while loop:
/* + 2 because of the '/' and the terminating 0 */
char *fullpath = malloc(arglen + strlen(ep->d_name) + 2);
if (fullpath == NULL) { /* deal with error and exit */ }
sprintf(fullpath, "%s/%s", path, ep->d_name);
/* use fullpath */
free(fullpath);