今天继续看C,看到对文件的读取写入这部分,然后就动手试试,是这段代码:
#include
include
void main(){
FILE _fqI=NULL;
fqI=fopen(“2.c”,”rt”);
if (fqI == NULL){
printf(“ERROR 1!”);
}
FILE _fqO=NULL;
fqO=fopen(“3.txt”,”wt”);
if (fqO == NULL){
printf (“ERROR 2!”);
}
char temp=’\0’;
while ( ! feof(fqI) ){
temp = fgetc(fqI);
if (temp != EOF){
fputc(temp,fqO);
}
}
fclose (fqO);
fclose (fqI);
getch();
}
然后就莫名其妙地遇到了错误:error C2275: 'FILE' : illegal use of this type as an expression.
这把我无奈的。。。于是google之,得到答案:
你定义的位置不对,纯C程序不能放在程序段中,要放在程序段头定义。
(这里)
真汗……这VC++ 6.0也真够垃圾的……
调整如下:#includeinclude
void main(){
FILE _fqI=NULL;
FILE _fqO=NULL;
char temp=’\0’;
fqI=fopen(“2.c”,”rt”);
if (fqI == NULL){
printf(“ERROR 1!”);
}
fqO=fopen(“3.txt”,”wt”);
if (fqO == NULL){
printf (“ERROR 2!”);
}
while ( ! feof(fqI) ){
temp = fgetc(fqI);
if (temp != EOF){
fputc(temp,fqO);
}
}
fclose (fqO);
fclose (fqI);
getch();
}
编译通过~~