我是 C 编程新手,我正在尝试编写一个程序来读取名为 input 的文件的上下文。
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch;
FILE *in;
in = fopen("input","r");
printf("The contents of the file are\n");
fscanf(in,"%c",&ch);
printf("%c",ch);
fclose(in);
return 0;
}
最佳答案
您的代码仅读取文件的第一个字符。没有循环来读取整个文件。这就是你的意图吗?
另外,检查文件打开是否成功。输入文件名是“input”吗?
关于c - 为什么我的 C 程序不能运行?从文件中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36193819/