| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 523 人关注过本帖
标题:大家看看我这程序哪里出了错
只看楼主 加入收藏
猫叔
Rank: 2
等 级:论坛游民
帖 子:15
专家分:11
注 册:2009-7-16
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
大家看看我这程序哪里出了错
#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");
   }
2009-09-06 10:10
幸运之星
Rank: 4
来 自:吉林
等 级:业余侠客
帖 子:275
专家分:239
注 册:2009-6-5
收藏
得分:7 
你指的是那里出错 ?程序大体能运行 但是有时好象指针 会遇到无效指令  这可能是我电脑的问题或是你的指针引用了不应该的地方
2009-09-06 10:21
masm500
Rank: 1
等 级:新手上路
帖 子:6
专家分:7
注 册:2008-10-24
收藏
得分:7 
2009-09-06 10:25
猫叔
Rank: 2
等 级:论坛游民
帖 子:15
专家分:11
注 册:2009-7-16
收藏
得分:0 
回复 2楼 幸运之星
我的问题是我的程序运行时会出错,比如输入第一个球队的信息,查看时却变成了数字;还有排名要几次查看球队情况才可以排好;还有程序一退出,再运行就没有我刚刚输入球队的信息了。总之我感觉我的程序好烂,要不是过几天老师要检查,我还真想把它删掉。做菜鸟的日子真苦啊~~
2009-09-06 11:01
快速回复:大家看看我这程序哪里出了错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018428 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved