猿问

求大佬解答c语言问题,无法运行


#include<stdio.h>

#include<stdlib.h>

#define M 4

struct student

{

int Num;

char Name[20];

int Score1;

int Score2;

int Average;

char Grade;

union 

{

char exemption;

int score3;

}SGrade;

};


char *search(struct student s1)

{

char *pt;

pt=NULL;

if(s1.Grade=='N')

{if(s1.Score1<60||s1.Score2<60||s1.SGrade.score3<60)

pt=&(s1.Name[20]);}

else

if(s1.Grade=='Y')

{if(s1.Score1<60||s1.Score2<60)

pt=&(s1.Name[20]);}


return(pt);

}

void Ave(struct student stu[M])

{

int i;

for(i=0;i<M;i++)

stu[i].Average=((stu[i].Score1)+(stu[i].Score2))/2;

}

void Rank(struct student *p)

{

struct student s1;

int i,j,min=(*p).Average;

for(i=0;i<M-1;i++)

{

for(j=1;j<M-i;j++)

{

if((*(p+i)).Average>(*(p+i+j)).Average)

{

min=(*(p+i+j)).Average;

s1=*(p+i);

*(p+i)=*(p+i+j);

*(p+i+j)=s1;

}

}

}

}

int main()

{


char *c;

int i;

struct student stu[M]={{1,"Tom",80,90,0,'Y','A'},{2,"Mike",60,70,0,'N',89},{3,"Angel",90,95,0,'Y','A'},{4,"Bobo",50,90,0,'N',78}};

struct student *p;

p=&stu[0];

for(i=0;i<M;i++)

{

printf("%d  %s  %d  %d  %d  %c  %s/n",stu[i].Num,stu[i].Name,stu[i].Score1,stu[i].Score2,stu[i].Average,stu[i].Grade,stu[i].SGrade);

}

    for(i=0;i<M;i++)

{

c=search(stu[i]);

if(c!=NULL)

printf("不及格的学生为%s/n",stu[i].Name);

}

    Ave(stu);

Rank(p);

for(i=0;i<M;i++)

{

printf("%d  %s  %d  %d  %d  %c  %c/n",stu[i].Num,stu[i].Name,stu[i].Score1,stu[i].Score2,stu[i].Average,stu[i].Grade,stu[i].SGrade.exemption);


}

FILE *fp;  

    char filename[10];  

    scanf("%s",filename);   

    if((fp=fopen(filename,"w"))==NULL) 

    {  

        printf("cannot open file\n"); 

exit(1);

}

for(i=0;i<M;i++)

fwrite(&stu[i],sizeof(stu[i]),1,fp);

fclose(fp);

putchar(10);

return 0;

}




qq_木枝_2
浏览 1004回答 1
1回答

qq_任小嗨_0

貌似少了分号
随时随地看视频慕课网APP
我要回答