c - C 编译错误

标签 c file header

关闭。这个问题需要details or clarity .它目前不接受答案。












想改进这个问题?通过 editing this post 添加详细信息并澄清问题.

7年前关闭。




Improve this question




从昨天开始,我在 C 语言中遇到了一个烦人的问题,而你是我最后的希望……我对 C 编程并不陌生

我制作了一个包含 5 个 .c 文件及其标题的项目。
我的 .c 之一正在使用文件,因此在每个函数中我都有:

FILE* file = NULL;
file = fopen("xxx", "x");

显然,我包括了 sdtio 和 stdlib..
但是对于 gcc,我每次都有这些错误对于每个函数..
file_rw.c: In function ‘load_scramble’:
file_rw.c:9:9: error: ‘file’ undeclared (first use in this function)
FILE* file = NULL;
      ^

请帮忙 !
谢谢 :)

最佳答案

这似乎不太可能,但我能想到的一种可能性是有一些奇怪的宏代替了 FILE , 加上其他东西,这使得这个简单的声明不正确。您可以通过 gcc 找到预处理翻译单元的输出。与 -E标志(详见 man gcc)。

例如:

#include <stdio.h>

#define FILE

int main(void)
{
    FILE* file = NULL;

    return 0;
}

编译到 gcc出现以下错误:
prog.c: In function 'main':
prog.c:6:8: error: 'file' undeclared (first use in this function)
  FILE* file = NULL;
        ^

关于c - C 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27891532/

相关文章:

c - 实现二叉搜索树

python - 访问目录中的所有文件

iOS - 运行 Swift 单元测试时找不到 'MyProject-Swift.h' 文件

c++ - 内置函数查找距离

c - 通过引用传递给函数时分配结构和填充字段

c - 标记结构初始化、函数及其参数

java - 加载 java 属性时出现问题

swift - 在 Swift 中获取远程文件顶部

nginx - Nginx 上的最大过期时间

html - CSS : How do I line up the elements in my header using css?