Concatenating file with path to get full path in C

后端 未结 4 1207
执笔经年
执笔经年 2021-01-03 07:57

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

4条回答
  •  长情又很酷
    2021-01-03 08:28

    You must not try to increase the size of argv[1] by strcat'ing to it (and changing it at all is a bad idea) - that will cause undefined behaviour. Instead, copy argv[1] into a suitable sized buffer and work with that:

    char path[1000];   // or some suitable size;
    strcpy( path, argv[1] );
    

提交回复
热议问题