| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 951 人关注过本帖
标题:各位帮我调试下啊,谢谢
只看楼主 加入收藏
zyx1989
Rank: 1
等 级:新手上路
帖 子:86
专家分:2
注 册:2011-9-17
结帖率:83.33%
收藏
已结贴  问题点数:20 回复次数:11 
各位帮我调试下啊,谢谢
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
typedef struct student
{
    int num;
    int age;
    char pc[20];
    char name[20];
    struct student *link;
}stud;

stud* creat(int n)
{
    stud *h,*p,*q;
    int i,main();
    FILE *fp;
    fp=fopen("d:\\KKK","r");//打开一个文件//
    if(fp==NULL)//检测文件能否打开//
    {
        printf("can not open file!");
        return(0);
    }
       h=NULL;//初始化头指针//
        
   
        
   

     
      
   
       system("cls");
      
      
    while(!feof(fp))
    {  
        
        p=(stud *)malloc(sizeof(stud));
        fread(p,sizeof(stud),1,fp);
        p->link=h;
        h=p;
    }
     h=h->link;
     
     if(h!=NULL)//创建记录前,先作检测是否已有记录//
     {
      printf("检测到记录,创建将覆盖记录,是否继续? y n\n");
     
      
     }
     else
     {
    h=(stud *)malloc(sizeof(stud));
    if(h==NULL)
    {
        printf("not enough memory!");
        return(0);
    }
     printf("学号\t年龄\t姓名\t电脑型号");
    h=NULL;
    for(i=0;i<=n;i++)
    {
        
      
        if((p=(struct student *)malloc(sizeof(stud)))==NULL)
            
            
            
        {
            printf("内存不足!");
            return(0);
        }
        printf("\n");
        scanf("%d",&p->num);

        
        scanf("%d",&p->age);
        scanf("%s",&p->pc);
        scanf("%s",&p->name);
        p->link=h;
        h=p;
      
    }
   return(h);
   

     }
      
 }


  stud* insert(stud *h)
  {
      stud *p,*q,*d,*i;
      
      
      p=h;
      int n;
      q=h->link;
      d=(stud *)malloc(sizeof(stud));
      if(d==NULL)
      {
          printf("内存不足!");
      }
      printf("请输入位置后的学号!\n");
      scanf("%d",&n);
      
      if(n!=p->num||n!=p->age)//如果插入节点不是头结点,则显示相关信息//
      printf("学号\t年龄\t姓名\t电脑型号\n");
      if(n==p->num||n==p->age)
      {
      printf("对不起,这里不能插入!\n");
      
      }
      
      else if
      
          (n==q->num||n==q->age)
      {
      
      scanf("%d",&d->num);
      scanf("%d",&d->age);
      scanf("%s",&d->pc);
      scanf("%s",&d->name);
      d->link=p->link;
      p->link=d;
      }
      else if(n!=p->num&&n!=q->num)
      {
         while(q->num!=NULL&&p->num!=NULL)
         {
              
              
              p=p->link;
              q=q->link;
              if(n==q->num)
             {
              printf("请输入要插入的信息!");
              scanf("%d",&d->num);
              scanf("%d",&d->age);
              scanf("%s",&d->pc);
              scanf("%s",&d->name);
              d->link=p->link;
              p->link=d;
               }
             break;
               
                        
         }
      }
     return(h);
  }  
  void search(stud *h)
  {
    stud *p;
    int m;
    printf("请输入需查学号!");
    scanf("%d",&m);
     
    printf("查找中...\n");
    system("cls");
    p=h;
     
    while(p!=NULL)
    {
   
        if(m==p->num||m==p->age)

        {   printf("学号\t年龄\t姓名\t电脑型号\n");
            printf("%d\t %d\t%s\t%s\n",p->num,p->age,p->pc,p->name);
           break;
         
        }
        else
        {
         p=p->link;
        }
   
     }
     
      if(p==NULL)
     printf("无该生信息!\n");      
     
   
   
   
  }
  

  stud *delet(stud *h)
  {
      stud *q,*p,*I;
      FILE *fp;
      int main();
      p=h;
      int n;
      q=h->link;
      
   

   

   

   
      printf("请输入要删除的学号!");
   
      scanf("%d",&n);
      if(n==p->num||n==p->age)
      {if(p->link!=NULL)
        *h=*(p->link);
        else
            free(p);
      }
      else if(n==q->num||n==q->age)
          p->link=q->link;
      else if(n!=p->num&&n!=q->num)
         while(q->link!=NULL&&p->link!=NULL)
         {
              
              
              p=p->link;
              q=q->link;        
             if(n==q->num||n==q->age)
              p->link=q->link;
         
         }
         
         
      return(h);
  }
void print(stud *h)
{
     stud *p;
     p=h;
     while(p!=NULL)
     {
         printf("%3d %d\n",p->num,p->age);
         p=p->link;
     }
}
void save(stud *h) //保存函数//
{
    stud *p;
    FILE *fp;
     p=h;//头指针赋给p//
    fp=fopen("d:\\KKK","w+");
    printf("保存中...\n");
    if(fp==NULL)
    {
        printf("memeory error!");
    }
   
    while(p!=NULL)
    {
        
        fwrite(p,sizeof(stud),1,fp);
        p=p->link;
   
  
    }
   
    fclose(fp);
   
    printf("save successful !\n");
}
stud *load()
{
    stud *p,*q,*h;
    FILE *fp;
    printf("读取中...");
   

    fp=fopen("d:\\KKK","r");//打开一个文件//
    if(fp==NULL)//检测文件能否打开//
    {
        printf("can not open file!");
        return(0);
    }
       h=NULL;//初始化头指针//
        
   
        
   

     
      
   
       system("cls");
      
      
    while(!feof(fp))
    {  
        
        p=(stud *)malloc(sizeof(stud));
        fread(p,sizeof(stud),1,fp);
        p->link=h;
        h=p;
    }
     h=h->link;
     if(h==NULL)
         printf("无记录!\n");
     else
     {
     printf("学号\t年龄\t姓名\t电脑型号\n");
     while(h!=NULL)
     {
         
         printf(" %2d",h->num);
         printf("%8d\t",h->age);
         printf("%s\t",h->pc);
         printf("%s",h->name);
          h=h->link;
          printf("\n");

    }
    fclose(fp);
     }
   
}

stud *cbc()
{
    stud *p,*q,*h;
    FILE *fp;

   

    fp=fopen("d:\\KKK","r");//打开一个文件//
    if(fp==NULL)//检测文件能否打开//
    {
        printf("can not open file!");
        return(0);
    }
       h=NULL;//初始化头指针//
        
   
        
   

     
      
   
      
      
      
    while(!feof(fp))
    {  
        
        p=(stud *)malloc(sizeof(stud));
        fread(p,sizeof(stud),1,fp);
        p->link=h;
        h=p;
    }
     h=h->link;
    p=h;//头指针赋给p//
    fp=fopen("d:\\KKK","w+");
   
    if(fp==NULL)
    {
        printf("memeory error!");
    }
   
    while(p!=NULL)
    {
        
        fwrite(p,sizeof(stud),1,fp);
        p=p->link;
   
  
    }
     
    fclose(fp);
     
   
}
stud *DEL()
{
    stud *p,*q,*h;
    FILE *fp;
    static n=0;
    printf("读取中...");
   

    fp=fopen("d:\\KKK","r");//打开一个文件//
    if(fp==NULL)//检测文件能否打开//
    {
        printf("can not open file!");
        return(0);
    }
       h=NULL;
        
   
       system("cls");
      
      
    while(!feof(fp))
    {  
        
        p=(stud *)malloc(sizeof(stud));
        fread(p,sizeof(stud),1,fp);
        p->link=h;
        h=p;
    }
      h=h->link;
      delet(h);
      printf("保存修改? y n\n");
      getchar();
      if(getchar()=='y')
      save(h);
     fclose(fp);
   
}        
stud *INF()
{
    stud *p,*q,*h;
    FILE *fp;
    printf("读取中...");
   

    fp=fopen("d:\\KKK","r");//打开一个文件//
    if(fp==NULL)//检测文件能否打开//
    {
        printf("can not open file!");
        return(0);
    }
       h=NULL;
        
    while(!feof(fp))
    {  
        
        p=(stud *)malloc(sizeof(stud));
        fread(p,sizeof(stud),1,fp);
        p->link=h;
        h=p;
    }   
        
   

     
      
   
       system("cls");
      
      
    while(!feof(fp))
    {  
        
        p=(stud *)malloc(sizeof(stud));
        fread(p,sizeof(stud),1,fp);
        p->link=h;
        h=p;
    }
     h=h->link;   
      insert(h);//接到返回指针,执行插入任务//
      printf("保存修改? y n\n");
      getchar();
      if(getchar()=='y')
     save(h);//接到插入函数返回指针,执行保存任务//
    fclose(fp);
   
   
}   

  
stud *SER()
{
    stud *p,*q,*h;
    FILE *fp;
    printf("读取中...");
   

    fp=fopen("d:\\KKK","r");//打开一个文件//
    if(fp==NULL)//检测文件能否打开//
    {
        printf("can not open file!");
        return(0);
    }
       h=NULL;
        
   
        
   

     
      
   
       system("cls");
      
      
    while(!feof(fp))
    {  
        
        p=(stud *)malloc(sizeof(stud));
        fread(p,sizeof(stud),1,fp);
        p->link=h;
        h=p;
    }
      h=h->link;   
      search(h);//获取返回指针,执行查找任务//
      fclose(fp);
   
   
}
int main()
{
    printf("载入中...\n");
    system("cls");
    int c,b,a,e,g,I,Q;
    static n=3;
    struct student *h;
    printf("\t********************欢迎使用学生宿舍管理系统***********************\n");
    printf("   \t\t0 添加记录\n");
    printf("   \t\t1 删除记录\n");
    printf("   \t\t2 显示所有记录\n");
    printf("   \t\t3 插入新记录\n");
    printf("   \t\t4 查找记录\n");
    printf("   \t\t5 退出\n");

    printf("请输入选项!\n");
  
     do
     {
         scanf("%d",&c);
         if(c!=0&&c!=1&&c!=2&&c!=3&&c!=4&&c!=5)
         printf("无相关选项,请重新选择!\n");
         
                  
         
   
         
     }while(c!=0&&c!=1&&c!=2&&c!=3&&c!=4&&c!=5);//如果选项不在所列范围,则循环提示重新输入//

    switch(c)
    {//
        
     
     case 0:
           h=creat(1);
     printf("5 保存\n6 返回\n");
     scanf("%d",&g);
     if(g!=5&&g!=6)
     do//判断是否有对应选项,否则提示重新输入//
     {
         
         printf("没有对应选项,请重新选择!");
         scanf("%d",&g);
     }while(g!=5&&g!=6);
     switch(g)
     {
     case 5:save(h);main();break;
     case 6: main();break;
     };break;
     case 1:DEL();
         n++;//记录调用DEL()函数的次数//
         if(n>3)//如果存储次数与3相除余数不为0,说明链表顺序相发,执行cbc()函数,该函数功能是再读取所存链表,然后再写入磁盘以使链表顺序恢复正常//
             cbc();
     printf("8 退出\n");
     scanf("%d",&I);
     do//判断是否有对应选项,否则提示重新输入//
     {
         if(I!=8)
         printf("没有对应选项,请重新选择!");
        
     }while(I!=8);
     switch(I)//作出选择,若为7则保存修改,为8则返回主菜单//
     {
     

     case 8:main();break;
     };break;
     case 2:load();
     printf("9 返回上一层\n");
     scanf("%d",&g);
     switch(g)
     {
     case 9:main();break;//选择9,调用主函数,返回主菜单//
     };break;
     case 3:INF();
     n++;
     if(n>3)
     cbc();
     printf("11 退出\n");
     scanf("%d",&a);//输入选择值//
     switch(a)
     {
     
     case 11:main();break;//选择11则直接回到主菜单//
     };break;
     case 4:SER();
         
     printf("12 返回上一层\n");
     scanf("%d",&Q);//输入选择的数//
     switch(Q)
     {
      case 12:main();break;//如果所选数为12,调用主函数,返回主菜单//
     };break;
     case 5:printf("您确定退出吗? y n\n");
           
           getchar();
         if(getchar()=='y')
         {
             if(getchar()!='\n')
             return(0);break;//退出,按任意键//
         }
         else
         {
             system("cls");
             main();break;
         }
              
}//
}   

搜索更多相关主题的帖子: 检测 include return 
2011-10-31 21:25
编程的乐趣
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:229
专家分:1027
注 册:2011-4-4
收藏
得分:3 
2011-10-31 21:27
zyx1989
Rank: 1
等 级:新手上路
帖 子:86
专家分:2
注 册:2011-9-17
收藏
得分:0 
???
2011-11-01 07:35
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:3 
什么代码呀,C语言基础没打好,又搞链表

总有那身价贱的人给作业贴回复完整的代码
2011-11-01 07:38
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:3 
这么一长串,也不说什么问题

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2011-11-02 07:11
zjk103
Rank: 2
等 级:论坛游民
帖 子:22
专家分:60
注 册:2011-5-13
收藏
得分:3 
表示很有压力。。。
2011-11-02 10:22
非死亡!
Rank: 8Rank: 8
来 自:四川
等 级:蝙蝠侠
帖 子:179
专家分:760
注 册:2011-10-31
收藏
得分:3 
这里是讨论学习的 不是来帮你改成的啊
你这么大一串 又没工资 叫谁帮你改?

能力 技巧
2011-11-02 12:12
wuyunxong
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:43
专家分:148
注 册:2011-10-26
收藏
得分:3 
汗流浃背……
2011-11-02 12:13
JimmyZeng21
Rank: 2
来 自:广东广州
等 级:论坛游民
帖 子:15
专家分:10
注 册:2011-11-1
收藏
得分:3 
新手的我看到這麼長我都怕怕了。
2011-11-02 12:52
zyx1989
Rank: 1
等 级:新手上路
帖 子:86
专家分:2
注 册:2011-9-17
收藏
得分:0 
就是有运行下,提出改进的意见
2011-11-02 13:19
快速回复:各位帮我调试下啊,谢谢
数据加载中...
 
   



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

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