|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<stdlib.h>
struct student
{
char name[50];
char xuehao[50];
int math;
int eng;
int total;
}stu1[5],stu2[5],*pp,*qq;
void main()
{
FILE *fp;
int i;
pp=stu1;
qq=stu2;
if((fp=fopen("D:\学习","wb+"))==NULL)
{
printf("Cannot open file\n");
getch();
exit(1);
}
for(i=0;i<5;i++,pp++)
scanf("%s %s %d %d",pp->name,pp->xuehao,&pp->math,&pp->eng);
pp=stu1;
fwrite(pp,sizeof(struct student),5,fp);
rewind(fp);
fread(qq,sizeof(struct student),5,fp);
for(i=0;i<5;i++,qq++)
{ qq->total=qq->eng+qq->math;
printf("%s\t%s %d %d %d\n",qq->name,qq->xuehao,qq->math,qq->eng,qq->total);}
fclose(fp);
}
这里为啥要pp=stu1 qq=stu2
第一个和第二个pp=stu分别是啥意思 为什么不能直接用指针pp |
|