不知道你要的是不是下面这个啊
c的源代码 Turbo C 2.0 测试正常
--------------------------------
#include<stdio.h>
struct school
{char schoolmark;
char studentname[20];
char sex;
int sportnumber;
int position;
int score;
struct school *next;
};
struct school *head,*this,*new;
main()
{char ch;
int flag=1;
head=NULL;
while(flag)
{printf("\nType 'E'or'e'to enter the record\n");
printf("type'L'or'l'to list the total score\n");
printf("type'D'or'd'to display the every record.\n");
ch=getchar();
getchar();
switch(ch)
{case 'e':
case 'E':new_record();break;
case 'L':
case 'l':listall();break;
case 'D':
case 'd':displayevery();break;
default:flag=0;
}}
}
new_record(void)
{char numstr[20];
new=(struct school*)malloc(sizeof(struct school));/*分配结点*/
if(head==NULL)
head=new;
else{this=head;
while(this->next!=NULL)
this=this->next;
this->next=new;
}this=new;
printf("\nEnter schoolmark like'a','b','c','d':");/*输入校名,以a,b,c,d为例*/
this->schoolmark=getchar();getchar();
printf("\nEnter studnetname:");/*输入学生姓名*/
gets(this->studentname);
printf("\n SEX:if boy enter 't',if girl enter 'f':");
this->sex=getchar();getchar();/*输入性别*/
printf("\nEnter sportnumber(if boy from 1 to 3,if girl from 4 to 5):");/*输入项目编号*/
gets(numstr);
this->sportnumber=atoi(numstr);
printf("\nEnter position(if sportnumber is odd,there is 5 positions;even has 3 positions):");/*输入比赛名次*/
gets(numstr);
this->position=atoi(numstr);
printf("\nEnter score(5positions to7,5,3,2,1;3position to 5,3,2):");/*输入相应的成绩*/
gets(numstr);
this->score=atoi(numstr);
this->next=NULL;
}
listall(void)
{int amalescore=0,afemalescore=0;
int bmalescore=0,bfemalescore=0;
int cmalescore=0,cfemalescore=0;
int dmalescore=0,dfemalescore=0;
if(head==NULL)
{printf("\nEmpty list\n");
return;}
this=head;
do{
if(this->schoolmark=='a')
{
if(this->sex=='t')
amalescore+=this->score;/*统计a学校男子总分*/
else afemalescore=afemalescore+this->score;/*统计a学校女子总分*/}
if(this->schoolmark=='b')
{
if(this->sex=='t')
bmalescore+=this->score;/*统计b学校男子总分*/
else bfemalescore=bfemalescore+this->score;/*统计b学校男子总分*/}
if(this->schoolmark=='c')
{
if(this->sex=='t')
amalescore+=this->score;/*统计c学校男子总分*/
else cfemalescore=cfemalescore+this->score;/*统计c学校男子总分*/}
if(this->schoolmark=='d')
{
if(this->sex=='t')
amalescore+=this->score;/*统计d学校男子总分*/
else dfemalescore=dfemalescore+this->score;/*统计d学校男子总分*/}
this=this->next;
}while(this!=NULL);
printf("\nthe Final Result of a school\n");/*打印a学校的成绩*/
printf("the male score is:%d\n",amalescore);
printf("the female score is:%d\n",afemalescore);
printf("the total score is:%d\n",amalescore+afemalescore);
printf("\nthe Final Result of b school\n");/*打印b学校的成绩*/
printf("the male score is:%d\n",bmalescore);
printf("the female score is:%d\n",bfemalescore);
printf("the total score is:%d\n",bmalescore+bfemalescore);
printf("\nthe Final Result of c school\n");/*打印c学校的成绩*/
printf("the male score is:%d\n",cmalescore);
printf("the female score is:%d\n",cfemalescore);
printf("the total score is:%d\n",cmalescore+cfemalescore);
printf("\nthe Final Result of d school\n");/*打印d学校的成绩*/
printf("the male score is:%d\n",dmalescore);
printf("the female score is:%d\n",dfemalescore);
printf("the total score is:%d\n",dmalescore+dfemalescore);
}
displayevery(void)
{if(head==NULL)
{printf("\nEmpty list\n");
return;}
this=head;
do{printf("record of a school\n");
if(this->schoolmark=='a')
{
printf("studentname:%s\n",this->studentname);
printf("sex:%c\n",this->sex);
printf("sportnumber:%d\n",this->sportnumber);
printf("position:%d\n",this->position);
printf("score:%d\n",this->score);
}
printf("record of b school\n");
if(this->schoolmark=='b')
{
printf("studentname:%s\n",this->studentname);
printf("sex:%c\n",this->sex);
printf("sportnumber:%d\n",this->sportnumber);
printf("position:%d\n",this->position);
printf("score:%d\n",this->score);
}
printf("record of c school\n");
if(this->schoolmark=='c')
{
printf("studentname:%s\n",this->studentname);
printf("sex:%c\n",this->sex);
printf("sportnumber:%d\n",this->sportnumber);
printf("position:%d\n",this->position);
printf("score:%d\n",this->score);
}
printf("\nrecord of d school\n");
if(this->schoolmark=='d')
{printf("record of d school");
printf("studentname:%s\n",this->studentname);
printf("sex:%c\n",this->sex);
printf("sportnumber:%d\n",this->sportnumber);
printf("position:%d\n",this->position);
printf("score:%d\n",this->score);
}
this=this->next;
}while(this!=NULL);
}