标题:求一个大神告诉我程序为什么进不去啊
只看楼主
wu1048781998
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-6-6
结帖率:0
已结贴  问题点数:20 回复次数:1 
求一个大神告诉我程序为什么进不去啊
#include<io.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#define  P  "学号:%-8ld姓名:%-8s班级:%-10s楼号:%-3s楼层:%-3s宿舍号:%-3s\n",p->num,p->name,p->classes,p->bnum,p->fnum,p->rnum
#define  N  sizeof(struct  stud)
manager();
main();
student();
struct  stud
{  
  long  num;
  char  name[20];
  char  classes[20];
  char  bnum[5];
  char  fnum[5];
  char  rnum[5];
  struct  stud  *next;   
};

struct  node
{
    char  mima[10];
    struct  node  *next;   
};





/*********************************************************************************************************/
//                                                                          录入学生信息
/*********************************************************************************************************/


struct  stud  *input_message()
{
  struct  stud  *p1,*p2,*head;  
  FILE  *fp;  
  fp=fopen("student_message.txt","wt");
  head=p2=(struct  stud  *)malloc(N);      /*head  p2指向头结点*/
  printf("请输入  学号  姓名  班级  楼号  楼层  宿舍号(输入0结束)\n");
  p1=(struct  stud  *)malloc(N);      /*p1指向第一个结点*/
scanf("%ld  %s  %s  %s  %s  %s",&p1->num,p1->name,p1->classes,p1->bnum,p1->fnum,p1->rnum);
if(p1->num!=0)
      fprintf(fp,"%ld  %s  %s  %s  %s  %s\n",p1->num,p1->name,p1->classes,p1->bnum,p1->fnum,p1->rnum);
while(p1->num!=0)
  {
        p2->next=p1;                            /*将新结点连接到表尾*/
    p2=p1;                                        /*p2指向新的表尾*/
    p1=(struct  stud  *)malloc(N);  /*p1指向新申请的结点*/
        scanf("%ld  %s  %s  %s  %s  %s",&p1->num,p1->name,p1->classes,p1->bnum,p1->fnum,p1->rnum);
        if(p1->num!=0)
    fprintf(fp,"%ld  %s  %s  %s  %s  %s\n",p1->num,p1->name,p1->classes,p1->bnum,p1->fnum,p1->rnum);
        
  }
  fclose(fp);
  p2->next=NULL;                        /*表尾结点next置空*/
  free(p1);                                  /*释放无效结点*/
  return  head;
}



/*********************************************************************************************************/
//                                                                          将文件中的信息存入单链表
/*********************************************************************************************************/


struct  stud  *inread()                                      /*将文件中的信息存入单链表*/
{
  struct  stud  *head,*p,*p1;
  FILE  *fp;
  fp=fopen("student_message.txt","rt");
  if(fp==NULL)
  {
      printf("读出文件出错,按任意键退出");
          exit(1);
  }
  head=(struct  stud  *)malloc(N);
  head->next=NULL;
  p=head;
  while(!feof(fp))
  {   
    p1=(struct  stud*)malloc(N);
    fscanf(fp,"%ld  %s  %s  %s  %s  %s\n",&p1->num,p1->name,p1->classes,p1->bnum,p1->fnum,p1->rnum);
    p->next=p1;              /*连接结点*/
    p=p1;
   
  }
  p->next=NULL;
  fclose(fp);
  return  head;
}

      

/*********************************************************************************************************/
//                                                                                  显示学生信息
/*********************************************************************************************************/

revise_message()
{
  FILE  *fp;
  struct  stud  *p;
  int  n=0,a,fsize;
  p=(struct  stud  *)malloc(N);
  fp=fopen("student_message.txt","rt");
  if(fp==NULL)
    {
        printf("\n      打开文件失败!");
        exit(1);
    }
  
  
  while(!feof(fp))                          /*文件未结束执行循环*/
{
    a=fileno(fp);
    fsize=filelength(a);      /*判断文件大小  */
        if(fsize==0)
        break;
    fscanf(fp,"%ld  %s  %s  %s  %s  %s\n",&p->num,p->name,p->classes,p->bnum,p->fnum,p->rnum);
    printf(P);
    n=1;
  }
fclose(fp);
if(n==0)  printf("无记录!!!\n");

}



/*********************************************************************************************************/
//                                                                                  将单链表的信息保存至文件中
/*********************************************************************************************************/


baocun(struct  stud  *p)
{
  struct  stud  *p1;
  FILE  *fp;
  fp=fopen("student_message.txt","wt");
  if(fp==NULL)
  {
      printf("写入文件出错,按任意键退出");
          exit(1);
  }
  for(p1=p->next;p1!=NULL;p1=p1->next)
    fprintf(fp,"%ld  %s  %s  %s  %s  %s\n",p1->num,p1->name,p1->classes,p1->bnum,p1->fnum,p1->rnum);  
  fclose(fp);

}



/*********************************************************************************************************/
//                                                                                  查询学生信息
/*********************************************************************************************************/



find_message()
{
        long  nnum;
    int  a,b,n,m;
    FILE  *fp;  
    struct  stud  *p;
        fp=fopen("student_message.txt","rt");
        p=(struct  stud  *)malloc(N);
    system("cls");
    printf("\n\n\n\n");
        printf("                                        ***********************************      \n");
        printf("                                                          欢迎进入宿舍管理系统                  \n");
        printf("                                        ***********************************      \n");  
        printf("\n                                                              1.返回上一级                          \n");
    printf("\n                                                              1.按学生学号查找                  \n");
        printf("\n                                                              2.按学生姓名查找                  \n");
        printf("\n                                                              3.按宿舍号查找                      \n");
        printf("\n\n\n");
        printf("请选择:");
        scanf("%d",&b);
        printf("\n\n\n");
   
//          按学生学生学号        
    if(b==1)
    {
    printf("\n请输入要查找的人的学号:\n");
        scanf("%ld",&nnum);
    while(!feof(fp))
    {
        fscanf(fp,"%ld  %s  %s  %s  %s  %s\n",&p->num,p->name,p->classes,p->bnum,p->fnum,p->rnum);
            if(p->num==nnum)
    {
                  printf(P);
              a=1;
      
      }                                                                /*标志*/
    }
    if(a!=1)    printf("\n没有找到此人!!!!\n");

    }      


//          按学生姓名查找
      if(b==2)
    {
        char  nname[20];
    printf("\n请输入要查找的人的姓名:");
        scanf("%s",&nname);
      
        while(!feof(fp))
    {  
        fscanf(fp,"%ld  %s  %s  %s  %s  %s\n",&p->num,p->name,p->classes,p->bnum,p->fnum,p->rnum);
    n=strcmp(p->name,nname);
    if(n==0)
    {
        printf(P);  
        a=1;}/*标志*/
    }
          if(a!=1)    printf("\n没有找到此人!!!!\n");

        }

      
            if(b==3)
    {
        char  nrnum[20];
    printf("\n请输入要查找的宿舍号:");
        scanf("%s",&nrnum);
      
        while(!feof(fp))
    {  
        fscanf(fp,"%ld  %s  %s  %s  %s  %s\n",&p->num,p->name,p->classes,p->bnum,p->fnum,p->rnum);
    m=strcmp(p->rnum,nrnum);
    if(m==0)
    {
        printf(P);  
        a=1;}/*标志*/
    }
          if(a!=1)    printf("\n没有找到此宿舍!!!!\n");

        }

      if(b==0)
        manager();




}




/*********************************************************************************************************/
//                                                                                删除学生信息
/*********************************************************************************************************/



delete_message(struct  stud  *p0)
{
          struct  stud  *p;
      long  nnum;
          int  a;  
          p=p0->next;
      printf("请输入要删除的人的学号:");
          scanf("%ld",&nnum);
      while(p!=NULL)
      {
          if(p->num==nnum)
        {
          p0->next=p->next;                        /*后续结点接到前面的结点上*/
                  printf("已删除此人!!!!");
                        a=1;                                                  /*标志常量*/
    }
              p0=p;                                                          /*推移指针*/
          p=p->next;
      }
    if(a!=1)
    printf("没有找到要删除的人!!!!");





}



/*********************************************************************************************************/
//                                                                            插入和修改学生信息
/*********************************************************************************************************/



change_message(struct  stud  *p0)
{
        long  nnum;
    int  a,b;
    system("cls");
    printf("\n\n\n\n");
        printf("                                        ***********************************      \n");
        printf("                                                          欢迎进入宿舍管理系统                  \n");
        printf("                                        ***********************************      \n");  
        printf("\n                                                              0.返回上一级                          \n");
        printf("\n                                                              1.插入学生信息                      \n");
        printf("\n                                                              2.修改学生信息                      \n");
        printf("\n\n\n");
        printf("请选择:");
        scanf("%d",&b);
        printf("\n\n\n");
   
        if(b==1)
    {
        struct  stud  *p;
        p=(struct  stud  *)malloc(N);
            printf("请输入要插入的学号  姓名  班级  楼号  楼层  宿舍号\n");
        scanf("%ld  %s  %s  %s  %s  %s",&p->num,p->name,p->classes,p->bnum,p->fnum,p->rnum);
        p->next=p0->next;                      /*后续结点连接到新结点后*/                              
        p0->next=p;                                  /*此时新接点处在头的位置*/
      

    }
   
   
    if(b==2)
    {
    printf("请输入要修改的人的学号:");
        scanf("%ld",&nnum);
    while(p0->next!=NULL)
    {
      p0=p0->next;                                                    /*指针后移*/
    if(p0->num==nnum)
    {
        printf("请修改此人的姓名  班级  楼号  楼层  宿舍号:");
            scanf("%s  %s  %s  %s  %s",p0->name,p0->classes,p0->bnum,p0->fnum,p0->rnum);
        printf("\n修改成功!!!!\n");
        a=1;
    }                                                                /*标志*/
    }
        if(a!=1)    printf("\n没有找到此人!!!!\n");

    }
        

        if(b==0)
        manager();


         
}



/*********************************************************************************************************/
//                                                                                统计学生信息
/*********************************************************************************************************/


   
dorm_message()
{
        int  a,b,m;
        FILE  *fp;
    struct  stud  *p;
        
    fp=fopen("student_message.txt","rt");
        p=(struct  stud  *)malloc(N);
    a=0;
    system("cls");
        printf("\n\n\n\n");
        printf("                                        ***********************************      \n");
        printf("                                                          欢迎进入宿舍管理系统                  \n");
        printf("                                        ***********************************      \n");  
        printf("\n                                                              0.返回上一级                          \n");
        printf("\n                                                              1.输入楼号统计人数              \n");
        printf("\n                                                              2.输入楼层号统计人数          \n");
        printf("\n                                                              3.输入宿舍号统计人数          \n");
        printf("\n\n\n");
        printf("请选择:");
        scanf("%d",&b);
        printf("\n\n\n");
   
//          按楼号统计      
    if(b==1)
    {
        char  nbnum[20];
        printf("\n请输入要统计的楼号:\n");
            scanf("%s",&nbnum);
        while(!feof(fp))
        {
        fscanf(fp,"%ld  %s  %s  %s  %s  %s\n",&p->num,p->name,p->classes,p->bnum,p->fnum,p->rnum);
            m=strcmp(p->bnum,nbnum);
        if(m==0)
        {
                    printf(P);
            a++;
        }
      }                                                                /*标志*/
          printf("\n该楼共有%d人\n",a);

    }      
  //          按楼层号统计      
    if(b==2)
    {
        char  nfnum[20];
        printf("\n请输入要统计的楼层号:\n");
            scanf("%s",&nfnum);
        while(!feof(fp))
        {
        fscanf(fp,"%ld  %s  %s  %s  %s  %s\n",&p->num,p->name,p->classes,p->bnum,p->fnum,p->rnum);
            m=strcmp(p->fnum,nfnum);
        if(m==0)
        {
                    printf(P);
            a++;
        }
      }                                                                /*标志*/
          printf("\n该楼层共有%d人\n",a);

    }      

//          按宿舍号统计      
    if(b==3)
    {
        char  nrnum[20];
        printf("\n请输入要统计的宿舍号:\n");
            scanf("%s",&nrnum);
        while(!feof(fp))
        {
        fscanf(fp,"%ld  %s  %s  %s  %s  %s\n",&p->num,p->name,p->classes,p->bnum,p->fnum,p->rnum);
            m=strcmp(p->rnum,nrnum);
        if(m==0)
        {
                    printf(P);
            a++;
        }
      }                                                                /*标志*/
          printf("\n该宿舍共有%d人\n",a);

    }      

        if(b==0)
        manager();


}



/*********************************************************************************************************/
//                                                                            排序学生信息
/*********************************************************************************************************/


   


paixu(struct  stud  *p0,  struct  stud  *p1,  struct  stud  *p2)
{
        p0->next  =  p2;
        p1->next  =  p2->next;
        p2->next  =  p1;

}

sort_message(struct  stud  *p0)      /*传递头指针*/
{
  int  i,a;
  int  flag;
  struct  stud  *p=NULL;
  system("cls");
      printf("\n\n\n\n");
      printf("                                        ***********************************      \n");
      printf("                                                          欢迎进入宿舍管理系统                  \n");
      printf("                                        ***********************************      \n");   
      printf("\n                                                                0.返回上一级                        \n");
      printf("\n                                                                1.升序排序                            \n");
      printf("\n                                                                2.降序排序                            \n");
  printf("\n\n\n");
printf("请选择:");
scanf("%d",&a);
printf("\n\n\n");
if(a==1)
{
  for  (i=0;  ;  i++)
  {
    flag  =  0;

    for  (p=p0;  p->next->next  !=  NULL;  p=p->next)        /*冒泡排序*/
    {
      if  (p->next->num  >  p->next->next->num)
      {
        flag  =  1;
        paixu(p,  p->next,  p->next->next);      
      }
    }

    if  (flag  ==  0)
    {
      printf("\n排序成功!!!!\n");break;
    }
  }
}
if(a==2)
{
      for  (i=0;  ;  i++)
  {
    flag  =  0;

    for  (p=p0;  p->next->next  !=  NULL;  p=p->next)
    {
      if  (p->next->num  <  p->next->next->num)
      {
        flag  =  1;
        paixu(p,  p->next,  p->next->next);      
      }
    }

    if  (flag  ==  0)
    {
            printf("\n排序成功!!!!\n");break;
    }
  }


}

  if(a==0)
      manager();


}




/*********************************************************************************************************/
//                                                                          管理员密码
/*********************************************************************************************************/


mima()
{
  int  n;
  int  a=3;
  struct  node  *p;
  char  rmima[10];
  FILE  *fp;
  fp=fopen("mima_message.txt","rt");
    p=(struct  node  *)malloc(sizeof(struct  node));
      
        while(!feof(fp))
    {   
        for(;a!=0;)
        {printf("请输入密码:\n");
      scanf("%s",rmima);
fscanf(fp,"%s\n",&p->mima);
    n=strcmp(p->mima,rmima);

    if(n==0)
          {
                  manager();
    }
        if(n!=0)   
      printf("\n密码错误,还有%d次机会\n",a-1);
          a--;
   
    }
    }
}





void  nmima()
{
    FILE  *fp;
    char  nmima[10];
    struct  node  *p;
    p=(struct  node  *)malloc(sizeof(struct  node));
    fp=fopen("mima_message.txt","wt");
    if(fp==NULL)
    {
        printf("\n      打开文件失败!");
        exit(1);
    }
        printf("请输入新密码");
    scanf("%s",nmima);
        strcpy(p->mima,nmima);
    fprintf(fp,"%s",p->mima);
    printf("修改成功!!\n");
    fclose(fp);

}
/*********************************************************************************************************/
//                                                                          管理员
/*********************************************************************************************************/




manager()
{
int  n;
char  m;
struct  stud  *head;
system("cls");
do
{
system("cls");
printf("                                        ***********************************      \n");
printf("                                                          欢迎进入宿舍管理系统                  \n");
printf("                                        ***********************************      \n");   
printf("\n                                                                0.返回上一级                        \n");
printf("\n                                                                1.录入学生信息                    \n");
printf("\n                                                                2.显示学生信息                    \n");
printf("\n                                                                3.查找学生信息                    \n");
printf("\n                                                                4.删除学生信息                    \n");
printf("\n                                                                5.修改学生信息                    \n");
printf("\n                                                                6.排序学生信息                    \n");
printf("\n                                                                7.统计宿舍信息                    \n");
printf("\n                                                                8.修改密码信息                    \n");
printf("\n请选择:\n");
scanf("%d",&n);
switch(n)
{
    case  0:  main();break;
    case  1:  input_message();break;
    case  2:  revise_message();break;
    case  3:  find_message();break;
    case  4:  head=inread();delete_message(head);baocun(head);break;
    case  5:  head=inread();change_message(head);baocun(head);break;
    case  6:  head=inread();sort_message(head);baocun(head);break;
    case  7:  dorm_message();break;
    case  8:  nmima();break;
    default:  printf("  !!!!错误!!!!  \n");break;

}
if(n==0)  break;
else  printf("\n要重新选择吗(y/n)\n");
m=getch();
  }while(m=='y'||m=='Y');

}



/*********************************************************************************************************/
//                                                                          学生
/*********************************************************************************************************/



student()
{
        
    int  b;
    char  m;
    do
{
    system("cls");
    printf("\n\n\n\n");
        printf("                                        ***********************************\n");
        printf("                                                          欢迎进入宿舍管理系统            \n");
        printf("                                        ***********************************\n");  
        printf("\n                                                              0.返回上一级                    \n");
        printf("\n                                                              1.查找学生信息                \n");
        printf("\n                                                              2.统计宿舍信息                \n");
        printf("\n\n\n");
        printf("请选择:");
        scanf("%d",&b);
        printf("\n\n\n");
        switch(b)
    {  case  0:main();break;
            case  1:find_message();break;
            case  2:dorm_message();break;
    }
printf("\n要重新选择吗(y/n)\n");
m=getch();
  }while(m=='y'||m=='Y');




}



/*********************************************************************************************************/
//                                                                          主函数
/*********************************************************************************************************/


main()
{
int  b;
system("cls");
printf("\n\n\n\n");
printf("                                        ***********************************\n");
printf("                                                          欢迎进入宿舍管理系统            \n");
printf("                                        ***********************************\n");  
printf("\n                                                              0.退出                                \n");
printf("\n                                                              1.管理员                            \n");
printf("\n                                                              2.学生                                \n");
printf("\n\n\n");
printf("请选择:");
scanf("%d",&b);
printf("\n\n\n");
switch(b)
{  case  0:break;
    case  1:mima();break;
    case  2:student();break;
}

}
搜索更多相关主题的帖子: classes include manager 姓名 
2017-06-06 15:13
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:20 
进不去是啥意思 啊

DO IT YOURSELF !
2017-06-06 15:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-477685-1-1.html




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

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