| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 360 人关注过本帖
标题:帮忙看一下这个程序是哪里出了问题
只看楼主 加入收藏
aitajiujiage
Rank: 2
等 级:论坛游民
帖 子:21
专家分:34
注 册:2010-5-10
结帖率:0
收藏
 问题点数:0 回复次数:0 
帮忙看一下这个程序是哪里出了问题
我是在Turbo c 中运行的,运行结果提示有太多错误,但我却无发找出真正的错误所在,有哪位高手可以不吝赐教一下,小弟感激不尽
#include "stdio.h"
#include  <string.h>
#include <stdlib.h>
#define Max 30
#define printf1  printf("------------------------------------------------------------------------------\n");
#define printf2  printf("学号--姓名---班级---年龄--性别----出生年月------地址------电话-------E-mail---\n");
#define printf3  printf("%3d%8s%4d%6d%4s%8d-%2d-%2d%12s%12s%16s\n",students.num,students.name,students.classes,students.age,students.sex,students.birthday.year,students.birthday.month,students.birthday.day,students.address,students.tele,students.E_mail );
int sum=0;

/*清屏函数*/
void clearscreen()
{
getchar();
system("cls");

}

struct date
  {  
  int  year;
  int month;
  int day;
  };
  struct stud_type
  {  
    int  num;
  char name[20];
        int  classes;
  int age;
  char sex[12];
  struct date birthday;
  char address[40];
  char tele[15];
  char E_mail[30];
  struct stud_type  *next;
  }students[Max],b[Max], t, *p,*q[Max],*next,*head=NULL,*p1,*h,*p2;
  /*保存信息*/
  int save_message(int sum)
{
      FILE  *fp;
    int i;
    if((fp=fopen("students' information.txt","wb"))==NULL)
    {
    printf("读文件错误!\n");
      return 0;
    }
    for(i=0;i<sum;i++)
  if(fwrite(&students,sizeof(struct stud_type),1,fp)!=1)
    printf("写文件错误!\n");
  fclose(fp);
  return i;
}

/*录入信息*/
int input_message()
{
    int i=sum,s=Max,k=0;
do
  {
        clearscreen();
  printf("录入学生信息(最多%d个)\n",s);
  printf1;
  printf(" \n          第%d个学生",i+1);
  printf("\n      学号:");
  scanf("%d",&students.num);
        
  if(students.num==0)
  break;
  printf("\n            学生姓名:");
  scanf("%s",students.name);
  printf("\n            班级:");
  scanf("%d",&students.classes);
  printf("\n            年龄:");
  scanf("%d",&students.age);
  printf("\n            性别:");
  scanf("%s",students.sex);
  printf("\n          出生年月(yyyy-mm-dd):");
        scanf("%d-%d-%d",&students.birthday.year,&students.birthday.month,&students.birthday.day);
  printf("\n          地址");
  scanf("%s",students.address);
  printf("\n          电话:");
  scanf("%s",students.tele);
  printf("\n          E_mail:");
  scanf("%s",students.E_mail);
  i++;
        k++;
  }while(i<Max);
      printf("\n          ---%d个学生信息输入完毕!--\n",i);
          printf(" \n      按回车键返回主菜单!\n");
  getchar();
      sum=k+sum;
      save_message(sum);
      return i;
  
}
    /*浏览信息*/

int read_message()
{
FILE *fp;
  int i=0;
  if((fp=fopen("students' information.txt","rt"))==NULL)
  { printf("\n\n                *****暂时还没有库存信息,按回车键返回主菜单!****\n");
  return 0;
  }
  while(feof(fp)!=1)
  {
  fread(&students,sizeof(struct stud_type),1,fp);
      if(students.num==0)
    break;
    else
    {
    i++;
    sum++;
    }
      
  }
  printf("\n\n                      文件中原有学生的信息:\n");
  printf1;
  printf2;
  printf1;
  for(i=0;i<sum;i++)
  {
  if(students.num!=0)
      printf3;
  }
  printf("\n\n\n\n        按回车键返回主菜单!");
fclose(fp);
return(i);
}

/*学生信息浏览*/
output_message()
{ int i=0,j=0,count=0,page=1;
  clearscreen();
printf("\n\n            ----学生信息表---\n                                  第 %d 页\n\n",page);
    printf1;
    printf2;

for(i=0;i<sum;i++)
{
  if(students.num!=0)
  printf3;
  if(i%8==0&&i!=0)
  {
    clearscreen();
          printf("\n\n            ----学生信息表---      第 %d 页\n\n",++page);
    printf1;
    printf2;
  }
}
return 0;
}

/*按学号排序*/                            /*选择排序法*/
  sort_message()
{   
        int i,j,k;
  clearscreen();
    for(i=0;i<sum-1;i++)
    {
    k=i;
    for(j=i+1;j<sum;j++)
    {
      if(students[k].num>students[j].num)
                k=j;
    }
    t=students;
    students=students[k];
    students[k]=t;
    }
        printf("\n\n\n");
        printf1;
    printf2;

    for(i=0;i<sum;i++)
    {
   
    printf3;
    }

            
  getchar();
  return 0;

}
/*两种查寻方式*/
  int  find_by_name()                    /*按姓名查找*/
  {
  int i, j=0;
  char inquire_name[20];
  clearscreen();
  printf(" \n        请输入要查学生的姓名:");
  scanf("%s",inquire_name);
    for(i=0;i<sum;i++)
    {
  
  if(strcmp(students.name,inquire_name)==0&&students.num!=0)
  {  
    printf("\n                        --%s的信息--\n",students.name);
    printf1;
    printf2;
    printf3;
  }
  else
    j++;
    }
  if(j==sum)
      printf("\n\n          该学生不存在!");
  getchar();
  return 0;
  }
  int find_by_num()                      /*按学号查找*/
  {
      int i,j=0,inquire;
  clearscreen();
  printf("\n          请输入要查学生的学号:");
  scanf("%d",&inquire);
  for(i=0;i<sum;i++)
  
  {
    if(inquire==students.num&&students.num!=0)
    {
    printf("\n                    --%s的信息--\n",students.name);
    printf1;
    printf2;
    printf3;
    }
  else
    j++;
  }
  if(j==sum)
          printf("\n\n            学号为%d的学生不存在!",inquire);
    getchar();
    return 0;
  }

  /*学生信息查询*/
int inquire_message()
{  
  int choice=0;
    do
    {
    clearscreen();
    printf("\n\n\n    ********学生信息查询*********\n\n");
    printf("                1.按学号查询;\n\n\n");
    printf("                2.按姓名查询;\n\n\n");
    printf("                0.返回主菜单.\n\n\n");
    printf("              请选择(0-2):");
    scanf("%d",&choice);
  switch(choice)
  {  
  case 2:    find_by_name();break;
  case 1:    find_by_num();break;
  case 0:    break;
  }
    }while(choice!=0);
return 1;
}
  /*学生信息的删除与修改*/
int range(int m)                  /*删除后对学号重新排序*/
{
  int i,j=0,k=0;
  for(i=0;i<sum;i++)
  {
  if(students.num!=0)
  {
    b[j]=students;
    j++;
  }
  else k++;
  }
  sum-=k;
  if(k!=0)
  {
      for(i=0;i<sum;i++)
  {
        students=b;
        students.num=i+1;
            }
  if(m==1)
          printf("  该生的信息已删除,并且全部学生学号也重新排序完毕!\n\n");
    printf("  按回车键返回!");
    getchar();
  }
    return 0;
    }
int delet_by_name()                      /*按姓名删除*/
{  
  char delet_name[20],i,f=0;
  printf(" \n\n      请输入要删除学生的姓名:");
  scanf("%s",delet_name);
  for(i=0;i<sum;i++)
  {
  if(strcmp(students.name,delet_name)==0)
  {
    students.num=0;
        printf("  %s的信息已删除,且全部学生学号也重新排列!",students.name);
        f=1;
    range(0);
               
    break;
  }
  }
        if(f==0)
  printf("  \n\n********经查并无该生信息!*************\n\n");
  getchar();
  return 0;
}
int delet_by_num()                  /*按学号删除*/
  {
  int delet_num=0,i,f=0;
  printf("\n\n              请输入您要删除学生的学号:");
            scanf("%d",&delet_num);
      for(i=0;i<sum;i++)
  {
    if(students.num==delet_num)
    {
    students.num=0;
      f=1;
      range(1);
                  
      break;
    }
  }
  if(f==0)
            printf(" \n\n        ********经查并无该生信息!*************\n\n");
  getchar();
  return 0;
    }


  int delet_message()
{
  int choice;
  do
  {  
    clearscreen();
  printf("      ********学生信息删除*********\n\n\n");
    printf("\n          1.按学生姓名删;\n\n");
    printf("            2.按学生学号删;\n\n");
        printf("            0.返回主菜单。\n\n");
        printf("          请选择(0-2):\n\n;");
    scanf("%d",&choice);
      switch(choice)
  {
        case 1: delet_by_name();break;
        case 2: delet_by_num();break;
        case 0: break;
  }
  }while(choice!=0);
  save_message(sum);
  return 1;
}
/*学生信息的修改*/
int  change(int i,int l)
  {  
  int choice,j;
  if(l==1)
  {
    for(j=0;j<sum;j++)
    {
    if(students[j].num==i)
      i=j;
    }
  }
  do
  {
    clearscreen();
    printf("\n\n  **********修改学生信息***********\n\n\n");
    printf("              1.修改班级;\n");
    printf("              2.修改年龄;\n");
          printf("              3.修改性别;\n");
    printf("              4.修改出生年月;\n");
    printf("              5.修改地址;\n");
    printf("              6.修改电话;\n");
    printf("              7.修改E-mail.");
    printf("              0.返回上级菜单。\n");
    printf("          请选择(0-7):\n");
        scanf("%d",&choice);
  switch(choice)
  {
  case 1: {  
      printf("    请输入班级:");
                  scanf("%d",&students.classes);
                  printf("      %s的班级修改完毕!",students.name);
      printf("      修改完毕!");
      getchar();
      break;
    }
  case 2: {  
        printf("    请输入年龄:");
      scanf("%d",&students.age);
                  printf("    %s的年龄修改完毕!",students.name);
                  getchar();
      break;
    }
  case 3:{
        printf("    请输入性别:");
      scanf("%s",students.sex);
                  printf("      %s的性别修改完毕!",students.name);
                    getchar();
      break;
      }
  case 4:{  
          printf("    请输入出生年月(yyyy-xx-zz):");
                  scanf("%d-%d-%d",&students.birthday.year,&students.birthday.month,&students.birthday.day);
                  printf("      %s的出生年月修改完毕!",students.name);
        getchar();
      break;
      }
  case 5:{
          printf("    请输入地址:");
      scanf("%s",students.address);
                  printf("      %s的地址修改完毕!",students.name);
        getchar();
      break;
      }
  case 6:{  
          printf("    请输入电话:");
      scanf("%s",students.tele);
                  printf("      %s的电话修改完毕!",students.name);
        getchar();
      break;
      }
  case 7:{
          printf("    请输入E-mail:");
      scanf("%s",students.E_mail);
                  printf("      %s的E-mial修改完毕!",students.name);
        getchar();
      break;
      }
  case 0: break;
  }
  }while(choice!=0);
  return 0;
  }

  int change_by_num()                  /*按学号修改*/
{
  int i=0,j=0;
  printf("    请输入学生学号:");
  scanf("%d",&j);
  if(j==0||j>=sum)
  {
  printf("    所查学生不存在!");
  getchar();
  return 0;
  }
  change(j,1);
  return 1;
}

  int change_by_name()                  /*按姓名修改*/
{
  int i;
  char change_name[20];
  printf("    请输入学生姓名:");
  scanf("%s",change_name);
  for(i=0;i<sum;i++)  
  if(strcmp(students.name,change_name)==0)
  {
    change(i,0);
    return 0;
  }
  
    printf("      所查学生不存在!");
    getchar();
    return 0;
}

  int change_message()
{
  int choice;
  do
  {
    clearscreen();
    printf("\n      *******学生信息修改*******\n\n\n");
    printf("              1.按姓名修改;\n\n");
    printf("              2.按学号修改;\n\n");
    printf("              0.返回上级菜单。\n\n");
    printf("        请选择(0-2):");
    scanf("%d",&choice);
    switch(choice)
    {
    case 1:  change_by_name();break;
    case 2:  change_by_num();break;
    case 0:  break;
    }
  }while(choice!=0);
  return 1;
}
/*学生信息更改*/

int renew_message()
{
  int choice;
  do
  {
  clearscreen();
  printf("\n\n\n  *******学生信息更改********\n\n");
  printf("              1.学生信息删除;\n\n\n");
  printf("              2.学生信息修改;\n\n\n");
        printf("              0.返回主菜单。\n\n\n");
  printf("            请选择(0-2):");
  scanf("%d",&choice);
      switch(choice)
  {
        case 1:  delet_message();break;
        case 2:  change_message();break;
  }
  }while(choice!=0);
  return 1;
}
  

/*主函数*/
int main()
{
  int  choice;
  read_message();
  do
  {
  clearscreen();
  printf("\n\n\n                        ****学生信息管理系统****\n\n");
  printf("                              1.学生信息录入;\n\n");
  printf("                              2.学生信息浏览;\n\n");
  printf("                              3.学生按学号排序;\n\n");
  printf("                              4.学生信息查询;\n\n");
  printf("                              5.学生信息的更改;\n\n");
  printf("                              0.退出系统.\n\n");
printf("                            请选择(0--5):");
      scanf("%d",&choice);
    switch(choice)
  {
        case 1: input_message();break;
        case 2: output_message();break;
  case 3: sort_message();break;
  case 4: inquire_message();break;
  case 5: renew_message();break;
  case 0:{
        save_message(sum);
                  printf("\n------以上学生信息已保存-(文件名:students' information.txt)\n");
                  getchar();

                  return 0;
        break;
      }
  }
  }while(choice!=0);
  return 0;  
}
搜索更多相关主题的帖子: include 电话 姓名 
2010-06-28 18:12
快速回复:帮忙看一下这个程序是哪里出了问题
数据加载中...
 
   



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

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