struct student
{
char name[20];
int number[20];
int age;
}stu[6],stu[6]={
{"p",136,19},
{"ni",295,19},
{"kui",210,20},
{"gn",204,19},
{"wangwei",209,19},
{"liyig",214,19}
};
void main(){
FILE *fp;
int i;
if( (fp=fopen("E:\ws.txt","wb"))==NULL)
{
printf("cannot open the file!");
getchar();
exit(1);
for(i=0;i<6;i++)
{
scanf("%s %d %d",stu[i].name,stu[i].number,stu[i].age);
}
}
fwrite((char)stu,sizeof(struct student),6,fp);
fclose(fp);
if((fp=fopen("ws.txt","rb"))==NULL);
{
exit(0);
}
fread((char)stu,sizeof(struct student),6,fp);
for(i=0;i<6;i++)
printf("%s %d %s",stu[i].name,stu[i].number,stu[i].age);
fclose(fp);
}*/
建议您将代码部分使用代码块显示。
– hellotim 5年前