c - 为什么我的 C 程序不能运行?从文件中读取

标签 c file io

我是 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/

相关文章:

Java:如何从文本文件中仅读取int数据来执行计算?

python - 在 Python 中使用 listdir 时出错

io - 将 Agda 程序输出到控制台

c++ - 带有字符显示的 vector

java - 文件在动态增加的文件中查找

c - Scanf 只读取句子中的一个单词

python - 知道文件名 :line_no where an import to my_module was made

c++ - Spy++ 显示错误结果?

c - 输入字符串数组不会显示?

c - 使用 libcurl 的 SMTP 邮件