C语言 打开和关闭文件
按照小甲鱼的课堂敲的代码,但为什么读取hello.txt文件后显示的是框框#include <stdio.h>
#include <stdlib.h>
int main(){
FILE *fp;
int ch;
if ((fp = fopen("hello.txt", "r")) == NULL){
printf("打开文件失败。\n");
exit(EXIT_FAILURE);
}
while (ch = getc(fp) != EOF){//EOF == end of fail(整形值)
putchar(ch);
}
fclose(fp);
return 0;
}
不是很懂C,个人认为可能是编码的原因? #include <stdio.h>
#include <stdlib.h>
int main(){
FILE *fp;
int ch;
if ((fp = fopen("hello.txt", "r")) == NULL){
printf("打开文件失败。\n");
exit(EXIT_FAILURE);
}
while ((ch = getc(fp)) != EOF){//EOF == end of fail(整形值)
putchar(ch);
}
fclose(fp);
return 0;
} https://blog.csdn.net/include_IT_dog/article/details/89435806 while那里的赋值运算符的优先级比不相等的判断低,所以要加上一个括号。
页:
[1]