我正在从文件中读取某个文件的路径,该文件作为应用程序的参数。 每个路径都写在一行上。我在给我这个错误的最后一条路径上遇到了问题:
Cannot open C:\Users\Utente\Desktop\find\try1.txtl¹v
这是我的代码:
struct filePath{
char path[255];
int fileOccurences;
};
struct filePath fPath[2];
char currentLine[255];
char path[255];
char word[30];
int i,ch;
int k = 0;
FILE * fInput = fopen(argv[1],"r");
if(fInput == NULL){ //check sull'apertura del file
fprintf(stderr,"Cannot open %s,exiting. . .\n",argv[1]);
exit(1);
}
while(!feof(fInput)){
for (i = 0; (i < (sizeof(path)-1) && ((ch = fgetc(fInput)) != EOF) && (ch != '\n')); i++){
fPath[k].path[i] = ch;
}
FPath[k].path[i] = '\0';
k = k + 1;
}
fclose(fInput);
for(int j = 0; j<2; j++){
FILE * fp = fopen(fPath[j].path,"r");
if(fp == NULL){
fprintf(stderr,fPath[j].path);
exit(1);
}
}
我只上传了程序中感兴趣的部分,这不是我确切编写代码的方式。因此,有人知道我该如何解决此问题并取消这些字符“ lv”。谢谢。