undeclared identifier - unsure as to why

牧云@^-^@ 提交于 2021-02-05 08:50:08

问题


I am just learning C

I have written the following:

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;
}

However i am getting these errors when trying to compile:
error C2065: 'FILE' : undeclared identifier
error C2065: 'fp' : undeclared identifier
warning C4552: '*' : operator has no effect; expected operator with side-effect

I'm unsure why as i believe FILE is a valid identifier in C

I am using Developer Command Prompt for VS2012 to compile


回答1:


FILE is declared in stdio.h. Add #include <stdio.h> to the top of your file.




回答2:


FILE is type from stdio.h. To use it you have to add:

#include <stdio.h>

at the top of your file. The result can be:

#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;
}


来源:https://stackoverflow.com/questions/39041040/undeclared-identifier-unsure-as-to-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!