| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1026 人关注过本帖, 1 人收藏
标题:100分找个小错.
只看楼主 加入收藏
五当家
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:2
帖 子:1112
专家分:3674
注 册:2010-10-20
结帖率:96.3%
收藏(1)
已结贴  问题点数:100 回复次数:17 
100分找个小错.
#include<stdio.h>
#include<malloc.h>
#define null 0
#define xian "---------------------------------------------------------------------------\n"
struct student
{
    int num;
    char name[20];
    char sex[10];
    int addr;
    float yuweng;
    float shuxue;
    float yingyu;
    struct student *next;
};
#define changdu sizeof(struct student)
int n;
struct student *scan()
{
    struct student *p;
    p=(struct student *)malloc(changdu);
    printf("请输入学生信息:\n");
    printf("学号:\n");
    scanf("%d",&p->num);
    printf("姓名:\n");
    scanf("%s",p->name);
    printf("性别:\n");
    scanf("%s",p->sex);
    printf("年龄:\n");
    scanf("%s",&p->addr);
    printf("语文成绩:\n");
    scanf("%f",&p->yuweng);
    printf("数学成绩:\n");
    scanf("%f",&p->shuxue);
    printf("英语成绩:\n");
    scanf("%f",&p->yingyu);
    return p;
}                                
//输入学生信息




struct student *chuangjian()
{
    struct student *head,*p1,*p2;
    p1=p2=(struct student *)malloc(changdu);
    p1=scan();
    head=null;
    while(p1->num!=0)
    {
        n++;
        if(n==1)
            head=p1;
        else
            p2->next=p1;
        p2=p1;   
        p1=(struct student *)malloc(changdu);
        p1=scan();
    }
    p2->next=null;
    return head;
}                    
//创建链表




void print(struct student *head)
{
    struct student *p;
        printf(xian);
        printf("|\t\t\t学\t生\t信\t息\t\t\t  |\n");
        printf(xian);
        printf("|  学 号  |   姓 名\t|   性 别   |  年 龄  |  语 文  | 数 学  | 英 语  |\n");
        p=head;
    while(head!=null)
    {   
            printf(xian);
            printf("|  %d   |   %s\t|     %s    |    %d   |  %5.2f  | %5.2f  | %5.2f  |\n",p->num,p->name,p->sex,p->addr,p->yuweng,p->shuxue,p->yingyu);
            p=p->next;
    }
    printf(xian);
}                        
//输出学生信息




struct student *del(struct student *head,int num)
{
    struct student *p1,*p2;
    if(head==null)
        printf("暂时没有学生信息.\n");
    p1=head;
    while(num!=p1->num&&p1->next!=null)
    {
        p2=p1;
        p1=p1->next;
    }
    if(num==p1->num)
    {
        if(p1==head)
            head=p1->next;
        else
            p2->next=p1->next;
        printf("删除学号为%d的学生信息\n",num);
    }
    else
        printf("没有这个学生的信息\n");
    return head;
}                    
//删除学生信息




struct student * insert(struct student *head)
{
    char x;
    struct student *p0,*p1,*p2;
    p1=head;
    printf("请问是否要插入学生信息?y或N\n");
    scanf("%c",&x);
    if(x=='n')
        return head;
    else
        if(x=='y')
    {
        printf("请输入要插入的学生信息:\n");
        p0=(struct student *)malloc(changdu);
        printf("学号:\n");
        scanf("%d",&p0->num);
        printf("姓名:\n");
        scanf("%s",p0->name);
        printf("性别:\n");
        scanf("%s",p0->sex);
        printf("年龄:\n");
        scanf("%s",&p0->addr);
        printf("语文成绩:\n");
        scanf("%f",&p0->yuweng);
        printf("数学成绩:\n");
        scanf("%f",&p0->shuxue);
        printf("英语成绩:\n");
        scanf("%f",&p0->yingyu);
    }
    else
    {
        printf("输入错误,系统会当作您输入的是No\n");
    }
    if(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;
    }
    return head;
}
//插入学生信息


                                    
int to()
{
    int m;
    printf("\t1-输入学生信息:\n");
    printf("\t2-插入学生信息:\n");
    printf("\t3-删除学生信息:\n");
    printf("\t4-输出学生信息:\n");
    printf("注意:在选2,3,4选项时,先选1进行创建,否则系统错误!!!!\n\n\n\n");
    printf("请选择\n");
    scanf("%d",&m);
    return m;
}   
//菜单


void main()
{
    struct student *head;
    char b;
    int num,m,i=0;
    printf("\t\t************************************************\n");
    printf("\t\t*                                              *\n");
    printf("\t\t*                                              *\n");
    printf("\t\t*                                  *\n");
    printf("\t\t*                                              *\n");
    printf("\t\t*                                              *\n");
    printf("\t\t*  本系统乃小五制作,版权所有,不可侵犯!!!!!!!   *\n");
    printf("\t\t************************************************\n\n\n\n\n\n");
    for(i=0;i<10;i++)
    {
        printf("是否进入主菜单?Y或N.\n");
        printf("请选择:");
        scanf("%s",&b);
        if(b=='Y')
        {
            m=to();
            switch(m)
            {
                case 1:    head=chuangjian();break;
                case 2: head=insert(head);break;
                case 3: printf("请输入要删除的学生学号:\n");
                    scanf("%d",&num);head=del(head,num);break;
                case 4: print(head);break;
                default :printf("输入错误\n");break;
            }
        }
        else
        {
            printf("\n\n\n\n\t\t******     *       *     ******       *******\n");
            printf("\t\t*     *     *     *      *     *      *\n");
            printf("\t\t*      *     *   *       *      *     *\n");
            printf("\t\t*     *       * *        *     *      *\n");
            printf("\t\t*****          *         *****        *******\n");
            printf("\t\t*     *        *         *     *      *\n");
            printf("\t\t*      *       *         *      *     *\n");
            printf("\t\t*     *        *         *     *      *\n");
            printf("\t\t******         *         ******       *******\n\n\n\n\n\n\n\n\n\n");
            printf("谢谢使用!!!\n\n\n\n");
            i=10;
        }
    }
}


   这里为什么就只能进行一次选择就不行了?????? 兄弟姐妹们帮我看看呢.



搜索更多相关主题的帖子: 小错 
2010-11-20 12:59
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:8 
你可以这样写啊!
程序代码:
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define null 0
#define xian "---------------------------------------------------------------------------\n"
struct student
{
    int num;
    char name[20];
    char sex[10];
    int addr;
    float yuweng;
    float shuxue;
    float yingyu;
    struct student *next;
};
#define changdu sizeof(struct student)
int n;
struct student *scan()
{
    struct student *p;
    p=(struct student *)malloc(changdu);
    printf("请输入学生信息:\n");
    printf("学号:\n");
    scanf("%d",&p->num);
    printf("姓名:\n");
    scanf("%s",p->name);
    printf("性别:\n");
    scanf("%s",p->sex);
    printf("年龄:\n");
    scanf("%s",&p->addr);
    printf("语文成绩:\n");
    scanf("%f",&p->yuweng);
    printf("数学成绩:\n");
    scanf("%f",&p->shuxue);
    printf("英语成绩:\n");
    scanf("%f",&p->yingyu);
    return p;
}                               
//输入学生信息




struct student *chuangjian()
{
    struct student *head,*p1,*p2;
    p1=p2=(struct student *)malloc(changdu);
    p1=scan();
    head=null;
    while(p1->num!=0)
    {
        n++;
        if(n==1)
            head=p1;
        else
            p2->next=p1;
        p2=p1;   
        p1=(struct student *)malloc(changdu);
        p1=scan();
    }
    p2->next=null;
    return head;
}                   
//创建链表




void print(struct student *head)
{
    struct student *p;
        printf(xian);
        printf("|\t\t\t学\t生\t信\t息\t\t\t  |\n");
        printf(xian);
        printf("|  学 号  |   姓 名\t|   性 别   |  年 龄  |  语 文  | 数 学  | 英 语  |\n");
        p=head;
    while(head!=null)
    {   
            printf(xian);
            printf("|  %d   |   %s\t|     %s    |    %d   |  %5.2f  | %5.2f  | %5.2f  |\n",p->num,p->name,p->sex,p->addr,p->yuweng,p->shuxue,p->yingyu);
            p=p->next;
    }
    printf(xian);
}                       
//输出学生信息




struct student *del(struct student *head,int num)
{
    struct student *p1,*p2;
    if(head==null)
        printf("暂时没有学生信息.\n");
    p1=head;
    while(num!=p1->num&&p1->next!=null)
    {
        p2=p1;
        p1=p1->next;
    }
    if(num==p1->num)
    {
        if(p1==head)
            head=p1->next;
        else
            p2->next=p1->next;
        printf("删除学号为%d的学生信息\n",num);
    }
    else
        printf("没有这个学生的信息\n");
    return head;
}                   
//删除学生信息




struct student * insert(struct student *head)
{
    char x;
    struct student *p0,*p1,*p2;
    p1=head;
    printf("请问是否要插入学生信息?y或N\n");
    scanf("%c",&x);
    if(x=='n')
        return head;
    else
        if(x=='y')
    {
        printf("请输入要插入的学生信息:\n");
        p0=(struct student *)malloc(changdu);
        printf("学号:\n");
        scanf("%d",&p0->num);
        printf("姓名:\n");
        scanf("%s",p0->name);
        printf("性别:\n");
        scanf("%s",p0->sex);
        printf("年龄:\n");
        scanf("%s",&p0->addr);
        printf("语文成绩:\n");
        scanf("%f",&p0->yuweng);
        printf("数学成绩:\n");
        scanf("%f",&p0->shuxue);
        printf("英语成绩:\n");
        scanf("%f",&p0->yingyu);
    }
    else
    {
        printf("输入错误,系统会当作您输入的是No\n");
    }
    if(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;
    }
    return head;
}
//插入学生信息


                                   
int to()
{
    int m;
    printf("\t1-输入学生信息:\n");
    printf("\t2-插入学生信息:\n");
    printf("\t3-删除学生信息:\n");
    printf("\t4-输出学生信息:\n");
    printf("注意:在选2,3,4选项时,先选1进行创建,否则系统错误!!!!\n\n\n\n");
    printf("请选择\n");
    scanf("%d",&m);
    return m;
}   
//菜单


void main()
{
    struct student *head;
    char b;
    int num,m,i=0;
    printf("\t\t************************************************\n");
    printf("\t\t*                                              *\n");
    printf("\t\t*                                              *\n");
    printf("\t\t*        学   生   管   理   系   统           *\n");
    printf("\t\t*                                              *\n");
    printf("\t\t*                                              *\n");
    printf("\t\t*  本系统乃小五制作,版权所有,不可侵犯!!!!!!!   *\n");
    printf("\t\t************************************************\n\n\n\n\n\n");
    while(1)
    {
        printf("是否进入主菜单?Y或N.\n");
        printf("请选择:");
        scanf("%s",&b);
        if(b=='Y')
        {
s:          m=to();
            switch(m)
            {
                case 1:    head=chuangjian();goto s;
                case 2: head=insert(head);goto s;
                case 3: printf("请输入要删除的学生学号:\n");
                    scanf("%d",&num);head=del(head,num);goto s;
                case 4: print(head);goto s;
                default :printf("输入错误\n");exit(0);
            }
        }
        else
        {
            printf("\n\n\n\n\t\t******     *       *     ******       *******\n");
            printf("\t\t*     *     *     *      *     *      *\n");
            printf("\t\t*      *     *   *       *      *     *\n");
            printf("\t\t*     *       * *        *     *      *\n");
            printf("\t\t*****          *         *****        *******\n");
            printf("\t\t*     *        *         *     *      *\n");
            printf("\t\t*      *       *         *      *     *\n");
            printf("\t\t*     *        *         *     *      *\n");
            printf("\t\t******         *         ******       *******\n\n\n\n\n\n\n\n\n\n");
            printf("谢谢使用!!!\n\n\n\n");
            i=10;
        }
    }
}



If You Want Something, Go Get It, Period.
2010-11-20 13:20
wujieru
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:1
帖 子:1108
专家分:1939
注 册:2010-10-9
收藏
得分:8 
你给100块我也不想帮你找  看的人晕
2010-11-20 18:25
fightingsss
Rank: 6Rank: 6
等 级:侠之大者
帖 子:97
专家分:471
注 册:2010-11-12
收藏
得分:8 
看了以后好有感觉!!!
2010-11-20 19:34
freedgun
Rank: 5Rank: 5
等 级:职业侠客
帖 子:147
专家分:302
注 册:2010-11-11
收藏
得分:8 
我看的眼睛都花了

有什么样的付出,就有什么样的收获!!
2010-11-20 19:49
天空绝尘
Rank: 1
等 级:新手上路
帖 子:7
专家分:8
注 册:2010-11-19
收藏
得分:8 
不懂,继续看……看懂了后,你肯定早就知道了。
2010-11-20 22:24
安普留香
Rank: 2
等 级:论坛游民
帖 子:77
专家分:62
注 册:2010-5-17
收藏
得分:8 
要进行多次选择的话就不能推出程序,你的程序进行一次输入后就退出了,没有循环判断
在输入模块处设置循环功能
2010-11-20 22:49
南国利剑
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:29
帖 子:1165
专家分:3536
注 册:2010-4-12
收藏
得分:8 
路过。能力有限啊。
呵呵

南国利剑
2010-11-21 01:59
五当家
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:2
帖 子:1112
专家分:3674
注 册:2010-10-20
收藏
得分:0 
我是创建的时候调用输入,创建中有循环.

经验积累中............
2010-11-21 09:35
袁野
Rank: 2
来 自:湖北省
等 级:论坛游民
帖 子:45
专家分:56
注 册:2010-10-13
收藏
得分:8 
回复 2楼 m21wo
进入“输入学生信息”怎么退出来
2010-11-21 13:48
快速回复:100分找个小错.
数据加载中...
 
   



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

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