| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 312 人关注过本帖
标题:帮忙看下是什么问题
只看楼主 加入收藏
xingyungirla
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-7-24
结帖率:0
收藏
已结贴  问题点数:100 回复次数:1 
帮忙看下是什么问题
程序在VC+可以运行正常。。但是在TC中运行到主页面的第一布输入数据department时就自动跳出了。。。这是怎么回事。。找不到错误吖。。文件名为data

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#define LEN sizeof(struct student)
int N=3;
struct student
{ int num;
  char name[20];
  double score[4];
  int pm;
  int classnumber;
  int grade;
  char department[30];
  struct student *next;
};
struct student stu[50];
void in();
void out();
void paixu();
void xianshi();
void pingjun();
void menuchoose();
void rate();
void tongji();
void delet(int m,int i);
void update();
void main()
{ int aa;
  menuchoose();
  scanf("%d",&aa);
  while(aa)
  { switch(aa)
     { case 1: in();break;
       case 2: out();break;
       case 3: paixu();break;
       case 4: xianshi();break;
       case 5: pingjun();break;
       case 6: rate();break;
       case 7: tongji();break;
       case 8: update();break;
       default:break;
     }
    getch();
    menuchoose();
    scanf("%d",&aa);
  }
}

void in()
{ int i,m=0;char c[2],b[2]="y";
  FILE *fp;
  if((fp=fopen("data.txt","rb"))==NULL)
     { printf("sorry!can't open the file,try again.\n");return;}
  while(!feof(fp))
  { if(fread(&stu[m] ,LEN,1,fp)==1) m++;}
  fclose(fp);
  if(m==0) printf("sorry!not any information,please input some.\n");
  else printf("hello!there are %d student informations,try again.\n",m);
  if((fp=fopen("data.txt","wb"))==NULL)
     { printf("fail to open the file,please try again.\n");return;}
  for(i=0;i<m;i++) fwrite(&stu[i] ,LEN,1,fp);
  printf("are you sure to add an information?(y/n):");scanf("%s",c) ;
  while(strcmp(b,c)==0)
   { printf("%d student number:",m+1);scanf("%d",&stu[m].num);
     printf("%d student name:",m+1);scanf("%s",stu[m].name);
     printf("%d student classnumber:",m+1);scanf("%d",&stu[m].classnumber);
     printf("%d student grade:",m+1);scanf("%d",&stu[m].grade);
     printf("%d student department:",m+1);scanf("%s",stu[m].department);
     printf("%d student english mark:",m+1);scanf("%lf",&stu[m].score[0]);
     printf("%d student maths mark:",m+1);scanf("%lf",&stu[m].score[1]);
     printf("%d student chinese mark:",m+1);scanf("%lf",&stu[m].score[2]);
     stu[m].score[3]=stu[m].score[0]+stu[m].score[1]+stu[m].score[2];
     if(fwrite(&stu[m] ,LEN,1,fp)!=1)
       { printf("%s sorry for save,please input %s information again.\n",stu[m].name); getch(); }
     else { printf("%s save successfully.\n",stu[m].name);m++;}
     printf("are you sure to input a student information?(y/n):");scanf("%s",c);
  }
  fclose(fp);
  printf("hello!done well.\n");
 }

void out()
 { FILE *fp;
   int i,m=0;
   if((fp=fopen("data.txt","rb"))==NULL)
      { printf("sorry!not any information mow,please input first.\n");return;}
   while(!feof(fp))
   { if(fread(&stu[m] ,LEN,1,fp)==1) m++;}
   fclose(fp);
   if(m==0) {printf("sorry!not any information mow,please input first.\n");fclose(fp);return;}
   if(stu[0].pm==0)
    { printf("\n the information now is):\n\n");
      printf("number\tname\tclassnumber\tgrade\tdepartment\tenglish mark\tmaths mark\tchinese mark\tadded mark \t\n");
      for(i=0;i<m;i++)
           { printf("%d\t%d\t%s\t%d\t%d\t%s\t%-2.1lf\t",stu[i].pm,stu[i].num,stu[i].name,stu[i].classnumber,stu[i].grade,stu[i].department,stu[i].score[0]);
                printf("%-2.1lf\t%-2.1lf\t%-4.1lf\n",stu[i].score[1],stu[i].score[2],stu[i].score[3]);
            }
     }
   else { printf("\n show information:\n\n");
          printf("mingci number  name\t\t english  maths  chinese  added mark\t\n");
          for(i=0;i<m;i++)
              { printf("%d\t%d\t%s\t%d\t%d\t%s\t%-2.1lf\t",stu[i].pm,stu[i].num,stu[i].name,stu[i].classnumber,stu[i].grade,stu[i].department,stu[i].score[0]);
                printf("%-2.1lf\t%-2.1lf\t%-4.1lf\n",stu[i].score[1],stu[i].score[2],stu[i].score[3]);
               }
         }
 }
 
void menuchoose()
{
  system("cls");
  printf("\n\n\n\n\n");
  printf("\t\t~*~*~*~*~*~*~*~*~C mark system~*~*~*~*~*~*~*~*~*~\n");
  printf("\t\t2\t 0. quit                                2\n");
  printf("\t\t0\t 1. input information                   0\n");
  printf("\t\t0\t 2. show student information            0\n");
  printf("\t\t7\t 3. paixu                               7\n");
  printf("\t\t3\t 4. chazhao delete show                 3\n");
  printf("\t\t3\t 5. ave mark and show the highest mark  3\n");
  printf("\t\t4\t 6. pass rate and good rate             4\n");
  printf("\t\t4\t 7. the whole number                    4\n");
  printf("\t\t \t 8. update                               \n");
  printf("\t\t~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~\n\n");
  printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t made by gaohan\n" );
  printf("\t\t\t  choose(0-8):");
}

void paixu()
{ FILE *fp;
  struct student a;
  int i=0,j=0,m=0;
  if((fp=fopen("data.txt","rb"))==NULL)
     { printf("sorry!not any information,please try after input information.\n");return;}
  while(!feof(fp)) if(fread(&stu[m] ,LEN,1,fp)==1) m++;
  fclose(fp);
  if(m==0) {printf("sorry!not any information?please try after input information.\n");return;}
  if((fp=fopen("data.txt","wb"))==NULL)
     { printf("sorry!open the file wrong!\n");return;}
  for(i=0;i<m-1;i++)
      for(j=0;j<m-1-i;j++)
          if(stu[j].score[3]<stu[j+1].score[3])
          { a=stu[j];stu[j]=stu[j+1];stu[j+1]=a;}
  for(i=0;i<m;i++) stu[i].pm=i+1;
  for(i=0;i<m;i++)
      if(fwrite(&stu[i] ,LEN,1,fp)!=1)
       { printf("%s wrong to save.\n",stu[i].name); getch();}
  fclose(fp);
  printf("paixu and save successful.\n");
}

void xianshi()
{ FILE *fp;
  int j,i,m=0;
  char c[2],b[2]="s",d[2]="x";
  if((fp=fopen("data.txt","rb"))==NULL)
     { printf("sorry!no information now,please input.\n");return;}
  while(!feof(fp))  if(fread(&stu[m],LEN,1,fp)==1) m++;
  fclose(fp);
  if(m==0) {printf("sorry!not any student information,please input.\n");return;}
  printf("please input the number of the student you want to look:");scanf("%d",&j);
  for(i=0;i<m;i++)
     if(j==stu[i].num)
     { printf("hello!the student you want has already be fond,do you want to show it or delete its information(s/x):");scanf("%s",c);
       if(strcmp(b,c)!=0&&strcmp(d,c)!=0) printf("input wrong.\n");
       else if(strcmp(b,c)==0) { delet(m,i);return;}
       else if(stu[i].pm==0)
        { printf("the information you want is(haven't paixu):\n\n");
          printf("number    name\t\t  english  maths  chinese    added mark\t\n");
          printf("%-8d%-20s%-10.1lf",stu[i].num,stu[i].name,stu[i].score[0]);
          printf("%-10.1lf%-10.1lf%-10.1lf\n",stu[i].score[1],stu[i].score[2],stu[i].score[3]);
          break;
         }
       else { printf("the student information you want (has paixu):\n\n");
              printf("mingci number  name\t\t english   maths  chinese    added mark\t\n");
              printf("%-5d%-8d%-20s%-10.1lf",stu[i].pm,stu[i].num,stu[i].name,stu[i].score[0]);
              printf("%-10.1lf%-10.1lf%-10.1lf\n",stu[i].score[1],stu[i].score[2],stu[i].score[3]);
              break;
             }
      }
  if(i==m) printf("sorry!no information\n");
}

void pingjun()
{ FILE *fp;
  int i,m=0;
  struct student high,low;
  double aver_score=0;
  if((fp=fopen("data.txt","rb"))==NULL)
     { printf("sorry!no student information,please input.\n");return;}
  while(!feof(fp))  if(fread(&stu[m],LEN,1,fp)==1) m++;
  if(m==0) {printf("sorry!no student information,please input.\n");fclose(fp);return;}
  if(m==1) {printf("there is only one student,no highest and lowest,ave mark:%-10.1lf\n",stu[0].score[3]);}
  else{ high=stu[0]; low=stu[0];aver_score=stu[0].score[3];
        for(i=1;i<m;i++)
         { aver_score+=stu[i].score[3];
           if(stu[i].score[3]>high.score[3]) high=stu[i];
           else if(stu[i].score[3]<low.score[3]) low=stu[i];
          }
        high.pm=1; low.pm=m;
        printf("the student's information of the highest mark\n");
        printf("mingci number  name\t\t english  maths  chinese  added mark\t\n");
        printf("%-5d%-8d%-20s%-10.1lf",high.pm,high.num,high.name,high.score[0]);
        printf("%-10.1lf%-10.1lf%-10.1lf\n",high.score[1],high.score[2],high.score[3]);
        printf("\n");
        printf("the student's information of the lowest mark:\n\n");
        printf("mingci number  name\t\t english  maths  chinese  added mark\t\n");
        printf("%-5d%-8d%-20s%-10.1lf",low.pm,low.num,low.name,low.score[0]);
        printf("%-10.1lf%-10.1lf%-10.1lf\n",low.score[1],low.score[2],low.score[3]);
        printf("\n");
        printf("the ave mark:%-10.1lf\n",aver_score/m);
       }
  fclose(fp);
 }

void rate()
{ FILE *fp;
  int m=0;int i,passcounter=0,goodcounter=0,test;
  char x;    
  double pass,good;
  if((fp=fopen("data.txt","rb"))==NULL)
     { printf("sorry!no student information,please input.\n");return;}
  while(!feof(fp))  if(fread(&stu[m],LEN,1,fp)==1) m++;
  if(m==0) {printf("sorry!no student information,please input.\n");fclose(fp);return;}
  while(1)
    {
        printf("input course number(1,2,3):");scanf("%d",&test);
        for(i=0;i<=m;i++)
        {
            if(stu[i].score[test-1]<60);
            else passcounter++;
            if(stu[i].score[test-1]<85);
            else goodcounter++;
        }
        pass=(double)(passcounter/m);
        good=(double)(goodcounter/m);
        printf("course %d pass rate is %lf",test,pass);
        printf("course %d good rate is %lf",test,good);
        printf("next scourse (y/n):");
        scanf("%s",&x);
        if(x=='n')
            break;
    }
  fclose(fp);
 }

void tongji()
{ FILE *fp;
  int m=0;
  if((fp=fopen("data.txt","rb"))==NULL)
     { printf("sorry!no student information,please input.\n");return;}
  while(!feof(fp))  if(fread(&stu[m],LEN,1,fp)==1) m++;
  if(m==0) {printf("sorry!no student information,please input.\n");fclose(fp);return;}
  printf("hello!there are %d students information.\n",m);
  fclose(fp);
 }

void delet(int m,int i)
{ FILE *fp;
  int j;
  if((fp=fopen("data.txt","rb"))==NULL)
     { printf("fail to open the file,please try again.\n");return;}
  for(j=i;j<m-1;j++)
     stu[j]=stu[j+1];
  m--;
  for(j=0;j<m;j++)
      if(fwrite(&stu[j] ,LEN,1,fp)!=1)
       { printf("%s save wrong.\n",stu[j].name); getch();}
  fclose(fp);
  printf("delete successful.\n");
 }


void update()
{
    FILE *fp;
    int test,m=0,j,i;
    char x;
    if((fp=fopen("data.txt","rb"))==NULL)
     { printf("sorry!can't open the file,try again.\n");return;}
     while(!feof(fp))
    { if(fread(&stu[m] ,LEN,1,fp)==1) m++;}
    fclose(fp);
    if(m==0) { in();}
    else printf("hello!there are %d student informations.\n",m);
    if((fp=fopen("data.txt","rb"))==NULL)
     { printf("fail to open the file,please try again.\n");return;}
    while(!feof(fp))
    { if(fread(&stu[m] ,LEN,1,fp)==1) m++;}
    fclose(fp);
    while(1)
    {
        for(i=0;i<m;i++) fwrite(&stu[i] ,LEN,1,fp);
        printf("input student number:");
        scanf("%d",&test);
        for(j=0;j<m;j++)
        {
            if(test==stu[j].num)
            {
                printf("change student name (%s): (y/n)",stu[j].name);scanf("%s",&x);
                if(x=='y') scanf("%s",stu[j].name);
                printf("change student english mark (%lf): (y/n)",stu[j].score[0]);scanf("%s",&x);
                if(x=='y') scanf("%lf",&stu[j].score[0]);
                printf("change student maths mark (%lf): (y/n)",stu[j].score[1]);scanf("%s",&x);
                if(x=='y') scanf("%lf",&stu[j].score[1]);
                printf("change student chinese mark (%lf): (y/n)",stu[j].score[2]);scanf("%s",&x);
                if(x=='y')scanf("%lf",&stu[j].score[2]);
                stu[m].score[3]=stu[j].score[0]+stu[j].score[1]+stu[j].score[2];
                break;
                
            }
        }fclose(fp);    
        printf("continue(y/n):");scanf("%s",&x);
        if(x=='n')
            break;
    }
    
}
2009-07-24 15:41
arthaszu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:90
专家分:163
注 册:2009-6-29
收藏
得分:100 
是不是显示过界了

To  four  years  in  each  other's
2009-07-24 23:52
快速回复:帮忙看下是什么问题
数据加载中...
 
   



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

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