大家看看我这程序哪里出了错
#include<stdio.h>#include<string.h>
#define bool int
#define true 1
#define false 0
#define LEN sizeof(struct team)
typedef struct team
{
char name[20];
int total;
int win;
int ping;
int lose;
int goal;
int begoal;
int feng;
int JSQ;
struct team *next;
}tel;
tel *head=NULL;
void Showmenu();
void Find();
void Display();
void Addteam();
void Modifyteam();
void Removeteam();
void SaveAndFree();
void Open();
tel *Findteam();
int main()
{char x;
bool quit=false;
Open();
while(!quit)
{
Showmenu();
scanf("%s",&x);
switch(x)
{case '0':
quit=true;
SaveAndFree();break;
case '1':
Addteam();break;
case '2':
Modifyteam();break;
case '3':
Removeteam();break;
case '4':
Find();break;
case '5':
Display();break;
default:
break;}
} return 0;}
void Showmenu()
{printf("\n***********************************\n");
printf("* 1.add a team *\n");
printf("* 2.modify a team *\n");
printf("* 3.delete a team *\n");
printf("* 4.search a team *\n");
printf("* 5.the condition of all team *\n");
printf("* 0.quit *\n");
printf("***********************************\n");
sleep(2);
printf("please choose:");}
void Addteam()
{tel *p1=NULL,*p2=NULL;
p1=(tel *)malloc(sizeof(tel));
printf("the team name:\n");
scanf("%s",p1->name);
printf("played game's number:\n");
scanf("%d",&p1->total);
printf("win the game:\n");
scanf("%d",&p1->win);
printf("equal the games:\n");
scanf("%d",&p1->ping);
printf("lose the games:\n");
scanf("%d",&p1->lose);
printf("goal number:\n");
scanf("%d",&p1->goal);
printf("be goaled number:\n");
scanf("%d",&p1->begoal);
p1->feng=(3*(p1->win)+p1->ping);
p1->JSQ=(p1->goal-p1->begoal);
p1->next=NULL;
if(NULL==head)
{head=(tel *)malloc(sizeof(tel));
head->next=p1;} else
{for(p2=head;p2->next!=NULL;p2=p2->next);
p2->next=p1;}}
void Find()
{tel *p=Findteam();
p->feng=3*p->win+p->ping;
p->JSQ=p->goal-p->begoal;
if(NULL==p)
printf("the team isnot exit!\n");
else
printf("find the team:\nname:%s\ntotal:%d\nwin:%d\nping:%d\nlose:%d\ngoal:%d\nbegoal:%d\nfeng:%d\nJSQ:%d\n",p->next->name,p->next->total,p->next->win,p->next->ping,p->next->ping,p->next->lose,p->next->goal,p->next->begoal,p->next->feng,
p->next->JSQ);}
tel *Findteam()
{char name[20];
tel *p=NULL;
printf("please input the team name:\n");
scanf("%s",name);
if(head==NULL)
{printf("there is no team record,please input the record then use this funcation!n");
return NULL;}
for(p=head;p->next!=NULL;p=p->next)
if(!strcmp(p->next->name,name))
return p;
return NULL;}
void Modifyteam()
{tel *p=Findteam();
if(NULL==p)
printf("the team isnot exit!\n");
else
{printf("the team's information you want to modify:\nname:%s\ntotal:%d\nwin:%d\nping:%d\nlose:%d \ngoal:%d\nbegoal:%d",p->next->name,p->next->total,
p->next->win,p->next->lose,p->next->goal,p->next->begoal);
printf("please input your new team name:\n");
scanf("%s",p->next->name);
printf("\ntotal games:\n");
scanf("%d",&p->next->total);
printf("\nwin ganme:\n");
scanf("%d",&p->next->win);
printf("\nping games:\n");
scanf("%d",&p->next->ping);
printf("\nlose games:\n");
scanf("%d",&p->next->lose);
printf("\nthe goals number:\n");
scanf("%d",&p->next->goal);
printf("\nthe begoals number:\n");
scanf("%d",&p->next->begoal);
p->next->next=NULL;}
}
void Removeteam()
{tel *temp=NULL;
tel *p=Findteam();
if(NULL==p)
printf("cannot find the team!\n");
else
{printf("the team you want to delete:\nname:%s",p->next->name);
temp=p->next;p->next=p->next->next;
free(temp);
}
}
void SaveAndFree()
{tel *p=NULL;
FILE *fp;
char *filename="f:\\book.txt";
if(head==NULL)
{printf("\nthe record is blank!\n");
return;}
else
p=head->next;
if((fp=fopen(filename,"wb"))==NULL)
{printf("\ncannot open the file!\n");
return;}
while(p!=NULL)
{fprintf(fp,"%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t\n",p->name,p->total,
p->win,p->ping,p->lose,p->goal,p->begoal,p->feng,p->JSQ );
p=p->next;}
printf("save up!\n");
fclose(fp);
for(;head->next!=NULL;)
{
p=head->next;
head->next=head->next->next;
free(p);}
free(head);
}
void Open()
{FILE *fp;
tel *p1=NULL,*p2=NULL,*temp=NULL;
if((fp=fopen("book.txt","r"))==NULL)
{printf("\n****this a new list****");
return;}
head=(tel*)malloc(sizeof(tel));
head->next=NULL;
temp=p2=head;
while(!feof(fp))
{p1=(tel *)malloc(LEN);
temp=p2;
p2->next=p1;
p2=p1;
fscanf(fp,"%s%d%d%d%d%d%d%d",p1->name,&p1->total,&p1->win,&p1->ping,&p1->lose,
&p1->goal,&p1->begoal);}
temp->next=NULL;
fclose(fp);
}
void Display()
{
char temp;
int t,w,pi,l,g,b,f,J;
tel *p=NULL;
if(head==NULL)
{printf("there is no team record,please input the record,then use it!\n");
return;
}
printf("========================================================================\n");
printf("name total win ping lose goal bgoal feng JSQ | | \n");
printf("========================================================================\n");
for(p=head->next;p!=NULL;p=p->next)
{if(p->feng<p->next->feng)
{strcpy(temp,p->name); strcpy(p->name,p->next->name); strcpy(p->next->name,temp);
t=p->total; p->total=p->next->total; p->next->total=t;
w=p->win; p->win=p->next->win; p->next->win=w;
pi=p->ping; p->ping=p->next->ping; p->next->ping=pi;
l=p->lose; p->lose=p->next->lose;p->next->lose=l;
g=p->goal;p->goal=p->next->goal;p->next->goal=g;
b=p->begoal;p->begoal=p->next->begoal;p->next->begoal=b;
f=p->feng;p->feng=p->next->feng;p->next->feng=f;
J=p->JSQ;p->JSQ=p->next->JSQ;p->next->JSQ=J;}
else if(p->feng==p->next->feng)
{ if(p->JSQ>p->next->JSQ)
{t=p->total;p->total=p->next->total;p->next->total=t;
w=p->win;p->win=p->next->win;p->next->win=w;
pi=p->ping;p->ping=p->next->ping;p->next->ping=pi;
l=p->lose;p->lose=p->next->lose;p->next->lose=l;
g=p->goal;p->goal=p->next->goal;p->next->goal=g;
b=p->begoal;p->begoal=p->next->begoal;p->next->begoal=b;
f=p->feng;p->feng=p->next->feng;p->next->feng=f;
J=p->JSQ;p->JSQ=p->next->JSQ;p->next->JSQ=J;}
} }
for(p=head->next;p!=NULL;p=p->next)
{printf("%s%8d%8d%8d%8d%8d%8d%8d%8d\n",p->name,p->total,p->win,p->ping,p->lose,p->goal,p->begoal,p->feng,p->JSQ);}
printf("\n====================================================================\n");
}