#include<stdio.h>
#include<string.h>
struct student
{
long num;
char name[10];
int eng;
int math;
int comp;
char addr[20];
}stu[10];
int main()
{
int n;
void fail(struct student *p);
struct student *q;
q=stu;
printf("please choose 1,2or3:");
scanf("%d",&n);
fail(stu);
return 0;
}
#include<stdlib.h>
void fail(struct student *p)
{
FILE *fp,*fpp;int sum,i;char c[50];
fp=fopen("D:\\ccc\\file1.txt","r");
fpp=fopen("D:\\ccc\\file2.txt","w");
if(fp==NULL||fpp==NULL)
{
printf("can't open file!\n");
exit(0);
}
printf("姓名 总成绩 地址\n");fgets(c,45,fp);
for(i=0;i<10;i++,p++)
{
fscanf(fp,"%d%d%d",p.eng,p.math,p.comp);//这句总出错
sum=(*p).eng+(*p).math+(*p).comp;
if(sum<180)
printf("%c,%d,%c\n",(*p).name,sum,(*p).addr);
}
}
fscanf(fp,"%d%d%d", &(p->eng),&(p->math),&(p->comp));
另外代码能不能写的规范一点:
FILE *fp,*fpp;int sum,i;char c[50];
分成三行些可以吧
fscanf(fp,"%d%d%d",p->eng,p->math,p->comp);
因为那是指针,要用->