c语言错误:'FILE' :illegal use of this type as an expression这是神马情况?#include "stdio.h"#include "string.h"#define K_MAX_PATH 255int main(int argc,char * argv[]){char pszTempPathName[K_MAX_PATH],*p;strcpy(pszTempPathName,argv[0]);p=strr
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/19 21:14:03
c语言错误:'FILE' :illegal use of this type as an expression这是神马情况?#include "stdio.h"#include "string.h"#define K_MAX_PATH 255int main(int argc,char * argv[]){char pszTempPathName[K_MAX_PATH],*p;strcpy(pszTempPathName,argv[0]);p=strr
c语言错误:'FILE' :illegal use of this type as an expression这是神马情况?
#include "stdio.h"
#include "string.h"
#define K_MAX_PATH 255
int main(int argc,char * argv[])
{
char pszTempPathName[K_MAX_PATH],*p;
strcpy(pszTempPathName,argv[0]);
p=strrchr(pszTempPathName,'\\')+1;
strcpy(p,"LastResu.bin");
FILE * fp=fopen(pszTempPathName,"wb");
//FILE * fp;
//fp=fopen(pszTempPathName,"wb");//这样写也不行
//if(fp==0){printf("Can not open file:LastResu.bin!");return 1;}
//fclose(fp);
}
编译结果:
D:\KCS\source\rst.c(15) :error C2275:'FILE' :illegal use of this type as an expression
c:\program files\microsoft visual studio\vc98\include\stdio.h(156) :see declaration of 'FILE'
D:\KCS\source\rst.c(15) :error C2065:'fp' :undeclared identifier
点击错误行,弹出stdio.h中的这些行,
#ifndef _FILE_DEFINED
struct _iobuf {
char *_ptr;
int _cnt;
char *_base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char *_tmpfname;
};
typedef struct _iobuf FILE;
#define _FILE_DEFINED
#endif
诸位大侠,到底哪里错了?
c语言错误:'FILE' :illegal use of this type as an expression这是神马情况?#include "stdio.h"#include "string.h"#define K_MAX_PATH 255int main(int argc,char * argv[]){char pszTempPathName[K_MAX_PATH],*p;strcpy(pszTempPathName,argv[0]);p=strr
代码没问题
怀疑是纯C环境 比较老的版本
所以要求变量定义只能在开头
你改成这样试试
#include "stdio.h"
#include "string.h"
#define K_MAX_PATH 255
int main(int argc,char * argv[])
{
char pszTempPathName[K_MAX_PATH],*p;
FILE * fp;
strcpy(pszTempPathName,argv[0]);
p=strrchr(pszTempPathName,'\\')+1;
strcpy(p,"LastResu.bin");
fp=fopen(pszTempPathName,"wb");
//FILE * fp;
//fp=fopen(pszTempPathName,"wb");//这样写也不行
//if(fp==0){printf("Can not open file:LastResu.bin!");return 1;}
//fclose(fp);
}