书上例子有问题求助!
#include<stdio.h>
#include <stdlib.h>
void main()
{FILE *fp;
char ch,st[20];
int i;
struct stu
{ char name[15];
char num[6];
float score;
}student;
if((fp=fopen("file2.txt","w"))==NULL)
{ printf("this file Cannot be opened!");
exit(1);
}
printf("input name:\n");
scanf("%s",name);
printf("input num:\n");
scanf("%s",num);
printf("input score:\n");
scanf("%f",&score);
fprintf(fp,"%s%s%7.2f\n",student.name,student.num,student.score);
fclose(fp);
if((fp=fopen("file2.txt","r"))==NULL)
{ printf("This file Cannot be opened!");
exit(0);
}
printf("output from file:\n");
while(fscanf(fp,"%s%s%f\n",student.name,student.num,student.score)!=EOF)
printf("%s%s%7.2f\n",student.name,student.num,student.score);
fclose(fp);
}
--------------------Configuration: helloc - Win32 Debug--------------------
Compiling...
helloc.cpp
D:\VC语言\helloc\helloc.cpp(17) : error C2065: 'name' : undeclared identifier
D:\VC语言\helloc\helloc.cpp(19) : error C2065: 'num' : undeclared identifier
D:\VC语言\helloc\helloc.cpp(21) : error C2065: 'score' : undeclared identifier
执行 cl.exe 时出错.
这怎么还要定义呢?
[解决办法]