C语言文件操作中遇到这样的问题: 程序:FILE *fp;编译时出现:undeclared identifier'FILE'

这是怎么回事,请高手指点

第1个回答  2011-10-24
FILE定义在stdio.h中。追问

两个头文件都写了呀
#include
#include ,这个作为子函数被调用,会不会是这方面有问题呢

追答

#include
#include

void wenjian(int num) { //数据存储文件
FILE *fp;
if((fp = fopen("shuju.txt","w")) == NULL) {
printf("can not open file shuju.txt!\n");
exit(0);
}
fprintf(fp,"%d",num);
if(fclose(fp)) {
printf("can not close file shuju.txt!\n");
exit(0);
}
}
在VC++ 6.0环境下,无错误编译信息。

第2个回答  2011-10-24
缺少头文件呗追问

我已经写了#include
#include

追答

完整代码的写出来~

追问

void wenjian(uint num)//数据存储文件
{
FILE *fp;
if((fp=fopen("shuju.txt","w"))==NULL)
{
printf("can not open file shuju.txt!\n");
exit(0);
}
fprintf(fp,"%d",num);
if(fclose(fp))
{
printf("can not close file shuju.txt!\n");
exit(0);
}
}

追答

#include
#include
typedef unsigned int uint;

void wenjian(uint num)
{
FILE *fp;
if((fp=fopen("shuju.txt","w"))==NULL)
{
printf("can not open file shuju.txt!\n");
exit(0);
}
fprintf(fp,"%d",num);
if(fclose(fp))
{
printf("can not close file shuju.txt!\n");
exit(0);
}
}

int main()
{
return 0;
}

vc6.0编译通过,会不会是什么其它的问题。

追问

我没有写你的这个主函数,我是作为子函数被其他函数调用的

本回答被提问者采纳