| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 818 人关注过本帖
标题:谁能帮我改正一下这个程序啊 万分感谢啊 !!!!!!!1
只看楼主 加入收藏
我爱下载102
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2013-1-5
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:12 
谁能帮我改正一下这个程序啊 万分感谢啊 !!!!!!!1

#include <stdio.h>
#include<stdlib.h>
#include<conio.h>
#include <string.h>
#include <io.h>
#define NULL 0
#define LEN sizeof(struct student)
 
struct student   
{
 long int num;
 char name[20];
 int age;
 char sex[4];
 char address[30];
 long int  tele_num;
 struct student *next;
};
int TOTAL_NUM = 0;
struct student *head = NULL;
void record();
void insert(struct student *stu);
void display(struct student *stu);
void displayAll();
void query();
void query_by_num();
void del_by_num();
void freeAll();
void devise(struct student *p);
//系统主菜单
void main()
{
    int choice;
    choice = -1;
 do
    {
        printf("\n\n\n");
        printf("\t\t\t--------------------------------\n");
        printf("\t\t\t|        学生信息管理系统      |\n");  
        printf("\t\t\t--------------------------------\n");               
        printf("\t\t\t+    [1]----录入学生信息       +\n");
        printf("\t\t\t+    [2]----浏览学生信息       +\n");
        printf("\t\t\t+    [3]----查询学生信息       +\n");
        printf("\t\t\t+    [4]----删除学生信息       +\n");
        printf("\t\t\t+    [0]----退出系统           +\n");
        printf("\t\t\t+*·*·*·*·*·*·*·*·*·*·+\n");
        printf("\t\t\t--------------------------------\n");
        printf("请输入您的选择:");
        scanf("%d", &choice);
        switch(choice)
        {
        case 0:
                freeAll();
                break;
        case 1:
                record();
                break;
        case 2:
                displayAll();
                break;
        case 3:
                query_by_num();
                break;
        case 4:
                del_by_num();
                break;

  default:
                printf("\n无效选项!");
                break;
        }
    }
    while(choice != 0);
}

//录入学生信息
void record()
{
 int i=0;
 struct student *p0,*head;   
 char a;
 do
 {
 p0 = (struct student *)malloc(LEN);
 printf("请输入学生的学号:");
 scanf("%ld",&p0->num);   
 fflush(stdin);
 printf("请输入学生的姓名:");
 scanf("%s",p0->name);
 fflush(stdin);
 printf("请输入学生的年龄:");
 scanf("%d",&p0->age);
 fflush(stdin);
 printf("请输入学生的性别:");
 scanf("%s",p0->sex);
 fflush(stdin);
 printf("请输入学生的籍贯:");
 scanf("%s",p0->address);
 fflush(stdin);
 printf("请输入学生的电话:");
 scanf("%ld",&p0->tele_num);
 fflush(stdin);

 insert(p0);
printf("\n是否继续输入另外一个学生信息?(y/n)");
 a=getchar();
i++;
}
 while(a=='y' && i<=50);
 TOTAL_NUM=i;
 head=p0;
}
 
void insert(struct student *stu)
{
 struct student *p0, *p1, *p2;
 
 p1 = head;
 p0 = stu;
 
 if(head == NULL)
 {
  head = p0;
  p0->next = NULL;
 }
 else
 {
  while((p0->num > p1->num)&&(p1->next != NULL))
  {
      p2 = p1;
   p1 = p1->next;
  }
  if(p0->num <= p1->num)
  {
   if(head == p1)
   head = p0;
   else
   p2->next = p0;
   p0->next = p1;
  }
  else
  {
   p1->next = p0;
   p0->next = NULL;
  }  
 }
 TOTAL_NUM++;
}
void display(struct student *p)
{
 printf("%ld\t%s\t%d\t%s\t%s\t%ld\t%s\n", p->num, p->name, p->age, p->sex,p->address, p->tele_num);
}
//浏览学生信息
void displayAll()
{
 struct student *p;
 printf("学生总数:%d\n", TOTAL_NUM);
 
 if(head != NULL)
 { p=head;//少了这个
  do
{
printf("%10d%10s%10d%10s%10s\n",p->num,p->name,p->age,p->sex);
p=p->next;
} while(p!=NULL);
 }
 printf("\n");
}
//查询学生信息
void query()
{
 int choice;
    choice = -1;
 do
    {
        printf("\n");
        printf("+--------------------+\n");
        printf("| 按学号查询  请按 1 |\n");
            
  printf("| 取消        请按 0 |\n");
        printf("+--------------------+\n");
        printf("请输入您的选择:");
        scanf("%d", &choice);
      
        switch(choice)
        {
            case 0:
                return;
            case 1:
                query_by_num();
                break;
                        
            default:
                printf("\n无效选项!");
                break;
        }
    }
    while(choice != 0);
}
//按学号查询学生信息
void query_by_num()
{
 int num;
 struct student *p1;
 printf("请输入学生的学号:");
 scanf("%ld", &num);
 if(head==NULL)
 {
  printf("无学生记录!\n");
  return;
 }
 p1=head;
 while(num!=p1->num && p1->next!=NULL)
  p1=p1->next;
 if(num == p1->num)
 {
  printf("\n 学 号\t姓 名\t年龄\t性别\t 地址\t        电话\t      \n");
  printf("-------------------------------------------------------------------------------  ");
  display(p1);
 }
 else
  printf("没有该学生记录,请检查!");
}

void  del_by_num()// 定义数据删除函数 //
{   
  int num;
  struct student *p1;
  printf("请输入要删除的学生学号:");
  scanf("%ld", &num);
  if(num==p1->num)
    {      
       p1=head;
       while(num!=p1->num && p1->next!=NULL)
       p1=p1->next;
       p1=head;
       printf("删除成功!%ld\n",num);
       display(p1->NULL);
       num=num-1;
    }
    else
        printf("\n 无效学号!\n");     
}

void freeAll()
{
 struct student *p1, *p2;
 p1=p2=head;
 while(p1)
 {
  p2=p1->next;
  free(p1);
  p1=p2;
 }
}
搜索更多相关主题的帖子: address long void display include 
2013-01-06 00:56
我爱下载102
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2013-1-5
收藏
得分:0 
执行的时候总是出现错误啊
2013-01-06 00:56
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
收藏
得分:2 
表示c语言我不是很会,基本的输入输出都还没用弄明白,要是c++我乐意帮忙。支持顶贴!
#include <stdio.h>
#include<stdlib.h>
#include<conio.h>
#include <string.h>
#include <io.h>
#define NULL 0
#define LEN sizeof(struct student)

struct student   
{
long int num;
char name[20];
int age;
char sex[4];
char address[30];
long int  tele_num;
struct student *next;
};
int TOTAL_NUM = 0;
struct student *head = NULL;
void record();
void insert(struct student *stu);
void display(struct student *stu);
void displayAll();
void query();
void query_by_num();
void del_by_num();
void freeAll();
void devise(struct student *p);
//系统主菜单
void main()
{
    int choice;
    choice = -1;
do
    {
        printf("\n\n\n");
        printf("\t\t\t--------------------------------\n");
        printf("\t\t\t|        学生信息管理系统      |\n");  
        printf("\t\t\t--------------------------------\n");               
        printf("\t\t\t+    [1]----录入学生信息       +\n");
        printf("\t\t\t+    [2]----浏览学生信息       +\n");
        printf("\t\t\t+    [3]----查询学生信息       +\n");
        printf("\t\t\t+    [4]----删除学生信息       +\n");
        printf("\t\t\t+    [0]----退出系统           +\n");
        printf("\t\t\t+*·*·*·*·*·*·*·*·*·*·+\n");
        printf("\t\t\t--------------------------------\n");
        printf("请输入您的选择:");
        scanf("%d", &choice);
        switch(choice)
        {
        case 0:
                //freeAll();//输入0是要退出系统,你这是写来清空链表?,表示不用了,退出了,就结束了嘛
                break;
        case 1:
                record();
                break;
        case 2:
                displayAll();
                break;
        case 3:
                query_by_num();
                break;
        case 4:
                //del_by_num();
                break;

  default:
                printf("\n无效选项!");
                break;
        }
    }
    while(choice != 0);
}

//录入学生信息
void record()
{
int i=0;
struct student *p0,*head;   
char a;
do
{
p0 = (struct student *)malloc(LEN);
printf("请输入学生的学号:");
scanf("%ld",&p0->num);   
fflush(stdin);
printf("请输入学生的姓名:");
scanf("%s",p0->name);
fflush(stdin);
printf("请输入学生的年龄:");
scanf("%d",&p0->age);
fflush(stdin);
printf("请输入学生的性别:");
scanf("%s",p0->sex);
fflush(stdin);
printf("请输入学生的籍贯:");
scanf("%s",p0->address);
fflush(stdin);
printf("请输入学生的电话:");
scanf("%ld",&p0->tele_num);
fflush(stdin);

insert(p0);
printf("\n是否继续输入另外一个学生信息?(y/n)");
a=getchar();
i++;
}
while(a=='y' && i<=50);
TOTAL_NUM=i;
head=p0;
}

void insert(struct student *stu)
{
struct student *p0, *p1, *p2;

p1 = head;
p0 = stu;

if(head == NULL)
{
  head = p0;
  p0->next = NULL;
}
else
{
  while((p0->num > p1->num)&&(p1->next != NULL))
  {
      p2 = p1;
   p1 = p1->next;
  }
  if(p0->num <= p1->num)
  {
   if(head == p1)
   head = p0;
   else
   p2->next = p0;
   p0->next = p1;
  }
  else
  {
   p1->next = p0;
   p0->next = NULL;
  }  
}
TOTAL_NUM++;
}
void display(struct student *p)
{
printf("%ld\t%s\t%d\t%s\t%s\t%ld\t%s\n", p->num, p->name, p->age, p->sex,p->address, p->tele_num);
}
//浏览学生信息
void displayAll()
{
struct student *p;
printf("学生总数:%d\n", TOTAL_NUM);

if(head != NULL)
{ p=head;//少了这个
  do
{
printf("%10d%10s%10d%10s%10s\n",p->num,p->name,p->age,p->sex);
p=p->next;
} while(p!=NULL);
}
printf("\n");
}
//查询学生信息
void query()
{
int choice;
    choice = -1;
do
    {
        printf("\n");
        printf("+--------------------+\n");
        printf("| 按学号查询  请按 1 |\n");
            
  printf("| 取消        请按 0 |\n");
        printf("+--------------------+\n");
        printf("请输入您的选择:");
        scanf("%d", &choice);
      
        switch(choice)
        {
            case 0:
                return;
            case 1:
                query_by_num();
                break;
                        
            default:
                printf("\n无效选项!");
                break;
        }
    }
    while(choice != 0);
}
//按学号查询学生信息
void query_by_num()
{
int num;
struct student *p1;
printf("请输入学生的学号:");
scanf("%ld", &num);
if(head==NULL)
{
  printf("无学生记录!\n");
  return;
}
p1=head;
while(num!=p1->num && p1->next!=NULL)
  p1=p1->next;
if(num == p1->num)
{
  printf("\n 学 号\t姓 名\t年龄\t性别\t 地址\t        电话\t      \n");
  printf("-------------------------------------------------------------------------------  ");
  display(p1);
}
else
  printf("没有该学生记录,请检查!");
}

/*void  del_by_num()// 定义数据删除函数 //你的删除函数有问题,思路应该是先去遍历链表,找到了才删除,找不到做特殊处理嘛要我改的话函数的给你重写
{   
  int num;
  struct student *p1;
  printf("请输入要删除的学生学号:");
  scanf("%ld", &num);
  if(num==p1->num)
    {      
       p1=head;
       while(num!=p1->num && p1->next!=NULL)
       p1=p1->next;
       p1=head;
       printf("删除成功!%ld\n",num);
       display(p1->NULL);    //这里的p1->NULL什么意思?
       num=num-1;
    }
    else
        printf("\n 无效学号!\n");     
}


/*void freeAll()//要清空链表,释放指针,就一个一个节点的删除
{
struct student *p1, *p2,*head;
p1=p2=head;
while(p1)
{
  p2=p1->next;
  free(p1);
  p1=p2;
}
}*/
//楼主你参考下,你就只有2个函数写的有问题,改改就可以啦

同学习......同进步....你帮我......我帮你.....上善若水.....
2013-01-06 12:44
bowendai
Rank: 1
等 级:新手上路
帖 子:1
专家分:2
注 册:2013-1-6
收藏
得分:2 
display(p1->NULL); 应该改成display(p1);
2013-01-06 16:45
我爱下载102
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2013-1-5
收藏
得分:0 
回复 3楼 不玩虚的
我太感谢你了!!!!!
2013-01-07 12:19
我爱下载102
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2013-1-5
收藏
得分:0 
回复 3楼 不玩虚的
话说我改过还是不成功
2013-01-07 12:28
allmy34
Rank: 2
等 级:论坛游民
帖 子:14
专家分:19
注 册:2012-12-29
收藏
得分:2 
#include <stdio.h>
#include<stdlib.h>
#include<conio.h>
#include <string.h>
#define LEN sizeof(struct student)

struct student
{
    long int num;
    char name[20];
    int age;
    char sex[4];
    char address[30];
    char tele_num[12];
    struct student *next;
};
int TOTAL_NUM = 0;
int choice = 5;
struct student *head = NULL;
void record();
void insert(struct student *stu);
void display(struct student *stu);
void displayAll();
void query();
void query_by_num();
void del_by_num();
void freeAll();
void devise(struct student *p);
// 系统主菜单
void main()
{
    do
    {
        printf("\n\n\n");
        printf("\t--------------------------------\n");
        printf("\t|        学生信息管理系统      |\n");
        printf("\t--------------------------------\n");
        printf("\t+    [1]----录入学生信息       +\n");
        printf("\t+    [2]----浏览学生信息       +\n");
        printf("\t+    [3]----查询学生信息       +\n");
        printf("\t+    [4]----删除学生信息       +\n");
        printf("\t+    [0]----退出系统           +\n");
        printf("\t--------------------------------\n");
        printf("\t--------------------------------\n");
        printf("请输入您的选择:");
        scanf("%d", &choice);
        switch (choice)
        {
        case 0:
            if (TOTAL_NUM)
                freeAll();
            return;
        case 1:
            record();
            break;
        case 2:
            displayAll();
            break;
        case 3:
            query();
            break;
        case 4:
            del_by_num();
            break;
        default:
            printf("\n无效选项!");
            break;
        }
    }
    while (1);
}

// 录入学生信息
void record()
{
    int i = 0;
    struct student *p0, *head;
    char a;
    do
    {
        p0 = (struct student *)malloc(LEN);
        printf("请输入学生的学号:");
        scanf("%ld", &p0->num);
        fflush(stdin);
        printf("请输入学生的姓名:");
        scanf("%s", p0->name);
        fflush(stdin);
        printf("请输入学生的年龄:");
        scanf("%d", &p0->age);
        fflush(stdin);
        printf("请输入学生的性别(m/f):");
        scanf("%s", p0->sex);
        fflush(stdin);
        printf("请输入学生的籍贯:");
        scanf("%s", p0->address);
        fflush(stdin);
        printf("请输入学生的电话:");
        scanf("%s", &p0->tele_num);
        fflush(stdin);

        insert(p0);

        if (i == 0)
            head = p0;
        printf("\n是否继续输入另外一个学生信息?(y/n)");
        a = getchar();
        scanf("%c", &a);
        i++;
    }
    while (a == 'y' && i <= 50);
    TOTAL_NUM = i;

}

void insert(struct student *stu)
{
    struct student *p0, *p1, *p2;

    p1 = head;
    p0 = stu;

    if (head == NULL)
    {
        head = p0;
        p0->next = NULL;
    }
    else
    {
        while ((p0->num > p1->num) && (p1->next != NULL))
        {
            p2 = p1;
            p1 = p1->next;
        }
        if (p0->num <= p1->num)
        {
            if (head == p1)
                head = p0;
            else
                p2->next = p0;
            p0->next = p1;
        }
        else
        {
            p1->next = p0;
            p0->next = NULL;
        }
    }
    TOTAL_NUM++;
}

void display(struct student *p)
{
    printf("\n%ld\t%s\t%d\t%s\t%s\t%s\t\n", p->num, p->name, p->age, p->sex,
           p->address, p->tele_num);
}

// 浏览学生信息
void displayAll()
{
    struct student *p;
    printf("学生总数:%d\n", TOTAL_NUM);
    if (head != NULL)
    {
        p = head;
        do
        {
            display(p);
            p = p->next;
        }
        while (p != NULL);
    }
    printf("\n");
}

// 查询学生信息
void query()
{
    int choice;
    choice = -1;
    do
    {
        printf("\n");
        printf("+--------------------+\n");
        printf("| 按学号查询  请按 1 |\n");
        printf("| 取消        请按 0 |\n");
        printf("+--------------------+\n");
        printf("请输入您的选择:");
        scanf("%d", &choice);
        switch (choice)
        {
        case 0:
            return;
        case 1:
            query_by_num();
            break;
        default:
            printf("\n无效选项!");
            break;
        }
    }
    while (choice != 0);
}

// 按学号查询学生信息
void query_by_num()
{
    int num;
    struct student *p1;
    printf("请输入学生的学号:");
    scanf("%ld", &num);
    if (head == NULL)
    {
        printf("无学生记录!\n");
        return;
    }
    p1 = head;
    while (num != p1->num && p1->next != NULL)
        p1 = p1->next;
    if (num == p1->num)
    {
        printf("\n学号\t姓 名\t年龄\t性别\t地址\t电话\n");
        printf("-------------------------------------\n  ");
        display(p1);
    }
    else
        printf("没有该学生记录!");
}

void del_by_num()
{
    int num;
    struct student *p1, *p2;
    printf("请输入要删除的学生学号:");
    scanf("%ld", &num);
    p1 = head;
    if (p1->num == num)
    {
        head = p1->next;
        TOTAL_NUM -= 1;
        free(p1);
    }
    else
    {
        while (num != p1->num && p1->next != NULL)
        {
            p2 = p1;
            p1 = p1->next;
        }
        if (num == p1->num)
        {
            p2->next = p1->next;
            TOTAL_NUM -= 1;
            free(p1);
            printf("学号为%ld的学生删除成功!\n", num);
        }
        else
            printf("\n 无效学号!\n");
    }
}

void freeAll()
{
    struct student *p1, *p2;
    p1 = p2 = head;
    while (p1)
    {
        p2 = p1->next;
        free(p1);
        p1 = p2;
    }
}
2013-01-07 16:47
李军威
Rank: 2
等 级:论坛游民
帖 子:4
专家分:22
注 册:2013-1-7
收藏
得分:2 
贴出错误
2013-01-07 17:13
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
收藏
得分:0 
嗯不错啊,有人帮你改好了,高手!同学习同进步。

同学习......同进步....你帮我......我帮你.....上善若水.....
2013-01-07 17:35
我爱下载102
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2013-1-5
收藏
得分:0 
回复 8楼 李军威
就是最后一个删除学生信息的函数不正确   各种各样的错误
2013-01-07 18:55
快速回复:谁能帮我改正一下这个程序啊 万分感谢啊 !!!!!!!1
数据加载中...
 
   



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

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