未声明的标识符 - 不确定为什么

问题描述:

我刚学习C未声明的标识符 - 不确定为什么

我写了下面的:

void main(void) 
{ 
    unsigned int curr_dat = 0; // The current dat file to use 
    unsigned char ch = 0;  // Key entered at keyboard 
    unsigned char lastkey = 0; // Last key entered (movement command) 
    FILE *fp; 
} 

但是我试图编译时遇到这些错误:
error C2065: 'FILE' : undeclared identifier
error C2065: 'fp' : undeclared identifier
warning C4552: '*' : operator has no effect; expected operator with side-effect

我不确定为什么,因为我认为FILE在C

我使用的开发者命令提示符下VS2012编译

+2

而'int main'而不是'void main' –

+1

谢谢@FredLarson,工作。不知道。 为什么int @AlterMann? – DNKROZ

+2

因为标准所以这样说) –

FILE is declared in stdio.h一个有效的标识符。将#include <stdio.h>添加到文件顶部。

FILE是从stdio.h类型。要使用它,你必须添加:

#include <stdio.h> 

在您的文件的顶部。结果可能是:

#include <stdio.h> 

void main(void) { 
    unsigned int curr_dat = 0; // The current dat file to use 
    unsigned char ch = 0;  // Key entered at keyboard 
    unsigned char lastkey = 0; // Last key entered (movement command) 
    FILE *fp; 
}