[英]Can't read file in visual c
I need to read some strings from a file and then sort them.我需要从文件中读取一些字符串,然后对它们进行排序。 Here's the file section of my code (functions and other tasks are working fine):
这是我的代码的文件部分(功能和其他任务工作正常):
#define FILENAME "E:\\Projects\\Es9Funz\\Words.txt"
int main() {
char string[MAX], word[MAX], sortedWord[MAX];
FILE* fp;
if ((fp = fopen("FILENAME", "r")) == NULL); {
fprintf(stderr, "Can't open %s\n", FILENAME);
return EXIT_FAILURE;
}
if (fscanf(fp, "%s", word) == EOF) {
fprintf(stderr, "File %s empty\n", FILENAME);
return EXIT_FAILURE;
}
do {
//some tasks
} while (fscanf(fp, "%s", word) != EOF);
fclose(fp);
return EXIT_SUCCESS;
}
so my output is: Can't open E:\Projects\Es9Funz\Parole.txt所以我的 output 是:无法打开 E:\Projects\Es9Funz\Parole.txt
but that's the same folder where my main is但这与我的主要文件夹相同
Thanks for your help谢谢你的帮助
In the code block:在代码块中:
if ((fp = fopen("FILENAME", "r")) == NULL); {
fprintf(stderr, "Can't open %s\n", FILENAME);
return EXIT_FAILURE;
Instead of "FILENAME" (Which is just a char*)而不是“文件名”(这只是一个字符*)
You should insert FILENAME as the constant defined (Use it as a variable)您应该将 FILENAME 作为定义的常量插入(将其用作变量)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.