| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1026 人关注过本帖, 1 人收藏
标题:100分找个小错.
取消只看楼主 加入收藏
五当家
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:2
帖 子:1112
专家分:3674
注 册:2010-10-20
结帖率:96.3%
收藏(1)
已结贴  问题点数:100 回复次数:2 
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
五当家
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:2
帖 子:1112
专家分:3674
注 册:2010-10-20
收藏
得分:0 
我是创建的时候调用输入,创建中有循环.

经验积累中............
2010-11-21 09:35
五当家
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:2
帖 子:1112
专家分:3674
注 册:2010-10-20
收藏
得分:0 
回复 13楼 落拓
在输出的时候还是有问题,能不能帮我看看呢?
总之谢谢各位啦!!

经验积累中............
2010-11-21 22:47
快速回复:100分找个小错.
数据加载中...
 
   



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

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