| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 534 人关注过本帖
标题:急需,求大神解救,改正C语言程序错误。
只看楼主 加入收藏
HL12346
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-6-20
结帖率:0
收藏
已结贴  问题点数:20 回复次数:7 
急需,求大神解救,改正C语言程序错误。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void input(struct stud *);
void search(struct stud *);
void modify(struct stud *);
void del(struct stud *);
void statistic(struct stud *);
void Print(struct stud *student);
struct Date
{
    int month;
    int day;
    int year;
};
struct stud
{
    int num;
    char name[25];
    char sex[10];
    struct Date birthday;
    struct Date starttime;
    char addr[20];
    char department[25];
    char major[25];
    char clas[25];
    struct stud *next;
};
static struct stud *Head=NULL;
//主函数
int main(void)
{
    int choice;
    do
    {
        system("CLS");                                  //清屏
        printf("\n\t==================学生证管理系统==================\n");
        printf("\t--------------------------------------------------\n");
        printf("\t***                                ***\n");
        printf("\t***      1--录入        2--查询      ***\n");
        printf("\t***                                ***\n");
        printf("\t***                                ***\n");
        printf("\t***      3--修改        4--删除      ***\n");
        printf("\t***                                ***\n");
        printf("\t***                                ***\n");
        printf("\t***      5--统计        0--退出      ***\n");
        printf("\t***                                ***\n");
        printf("\t--------------------------------------------------\n");
        printf("\t\t请您在上述功能中选择(0--5):");
        scanf("%d",&choice);
        while(choice<0||choice>5)                         //保证用户正确操作
        
        {
            printf("\n您的输入有误,请重新选择:");
            scanf("%d",&choice);
        }
        switch(choice)
        {
        case 1:input(Head);break;                    //调用录入函数
        case 2:search(Head);break;                      //调用查询函数
        case 3:modify(Head);break;                   //调用修改函数
        case 4:del(Head);break;                         //调用删除函数  
        case 5:statistic(Head);break;                  //调用统计函数
        case 0:exit(0);
        }
    }while(1);                              //无限循环,直到用户选择0退出程序
    return 0;
}
//录入函数
void input(struct stud*p)
{
    struct stud*New=NULL,*This=NULL;
    New=(struct stud*)malloc(sizeof(struct stud));         //开辟一个新结点的存储空间   
    if(p==NULL)                                      //将新结点链接到表尾
    {
        p=New;
        Head=p;
    }
    else
    {
        This=p;
        while(This->next!=NULL)
            This=This->next;
        This->next=New;
    }
    This=New;                                        //输入新结点数据
    printf("\n\t==================学生证管理系统==================\n");
    printf("\t******************录入新信息******************\n");
    printf("请用英文输入新添加学生的信息:");
    printf("\n学号:");
    scanf("%d",&(This->num));
    printf("\n姓名:");
    scanf("%s",This->name);
    printf("\n性别(male/female);");
    scanf("%s",This->sex);
    printf("\n出生年月(月/日/年如8/6/1986):");
    scanf("%d/%d/%d",&This->birthday.day,&This->birthday.month,&This->birthday.year);
    printf("\n入学时间(月/日/年如9/1/2007):");
    scanf("%d/%d/%d",&This->starttime.day,&This->starttime.month,&This->starttime.year);
    printf("\n籍贯:");
    scanf("%s",This->addr);
    printf("\n系别:");
    scanf("%s",This->department);
    printf("\n专业:");
    scanf("%s",This->major);
    printf("\n班级:");
    scanf("%s",This->clas);
    This->next=NULL;
    Print(This);                                                  //打印新结点信息
    printf("\n您已成功添加了一条新信息.");
    printf("\n按任意键返回主目录!");
    getchar();
    getchar();
}
//查询函数
void search(struct stud *Head)
{
    int n;
    struct stud *This;                                   //打印选择界面
    printf("\n\n\t==================学生证管理系统==================");
    printf("\n\t***************************查询****************************\n");
    printf("\t""\t***                                                ***\n");
    printf("*** *           1----------按学号查询             ***\n");
    printf("\t**                                                ***\n");
    printf("\t***                                                ***\n");
    printf("\t***           2----------按姓名查询             ***\n");
    printf("\t***                                                ***\n");
    printf("\t***                                                ***\n");
    printf("\t***           3----------按班级查询             ***\n");
    printf("\t***                                           ***\n");
    printf("\t********************************************************\n");
    printf("\t\t请您在上述功能中选择(1--3):");
    scanf("%d",&n);
    while(n<1||n>3)                                    //保证用户正确操作
    {
        printf("\n您的输入有误,请重新选择:");
        scanf("%d",&n);
    }
    switch(n)                                          //选择相应的查询方式
    {
    case 1:                                            //按学号查询
        This=Head;
        int temp1;
        printf("\n请输入您要查询的学生的学号:");
        scanf("%d",&temp1);
        while(This!=NULL)
        {
            if(temp1==This->num)
                break;
            This=This->next;
        }
        if(This==NULL)
            printf("\n没有找到该学生!");
        else
        {
            printf("\n\t已找到该学生:");
            Print(This);
        }
        break;
    case 2:                                            //按姓名查询
        This=Head;
        char temp2[20];
        printf("\n请输入您要查询的学生的姓名:");
        scanf("%s",temp2);
        while(This!=NULL)
        {
            if(strcmp(temp2,This->name)==0)break;
            This=This->next;
        }
        if(This==NULL)
            printf("\n没有找到该学生!");
        else
        {
            printf("\n\t已找到该学生:");
            Print(This);
        }
        break;
    case 3:                                             //按班级查询
        This=Head;
        char temp3[20];int i=0;
        printf("\n请输入您要查询的班级名称:");
        scanf("%s",temp3);
        if(This==NULL)
            printf("\n没有找到该班级学生的信息!");
        else
        {
            while(This!=NULL)
            {
                if(strcmp(temp3,This->clas)==0)
                {
                    Print(This);
                    i++;
                }
                This=This->next;
            }
            if(i==0)
                printf("\n没有找到该班级学生的信息!");
            else
            {
                printf("\n*************************************************\n");
                printf("已找到%d个该班的学生,具体成员如上.",i);
            }
        }
        break;
    }
    printf("\n按任意键返回主目录!");
    getchar();
    getchar();
}
//修改函数
void modify(struct stud *Head)
{
    int m,n;
    struct stud *This=Head;
    printf("\n请输入您要修改的学生的学号:");
    scanf("%d",&m);
    while(This!=NULL)                              //查找相应学号的学生
    {
        if(m==This->num)
            break;
        This=This->next;
    }
    if(This==NULL)
        printf("\n没有找到该学生的信息!");
    else
    {
        printf("\n已找到该学生.");
        Print(This);                        //打印该学生的信息     //打印修改项目
        printf("\n\t==================学生证管理系统==================");
        printf("\n\t**************************修改****************************\n");
        printf("\t***                                       ***\n");
        printf("\t***       1--学号         2--姓名       ***\n");
        printf("\t***                                       ***\n");
        printf("\t***       3--性别         4--出生日期   ***\n");
        printf("\t***                                       ***\n");
        printf("\t***       5--入学日期     6--籍贯       ***\n");
        printf("\t***                                       ***\n");
        printf("\t***       7--系别         8--专业       ***\n");
        printf("\t***                                       ***\n");
        printf("\t***       9--班级         0--返回       ***\n");
        printf("\t***                                       ***\n");
        printf("\t************************************************************\n");
        printf("\t\t请选择您要修改的项目:");
        scanf("%d",&n);
        while(n<0||n>9)                                    //保证用户正确操作
        {
            printf("\n您的输入有误,请重新选择:");
            scanf("%d",&n);
        }
        switch(n)
        {
        case 1:
            printf("\n请输入修改后的学号:");
            scanf("%d",&This->num);
            break;
        case 2:
            printf("\n请输入修改后的姓名:");
            scanf("%s",This->name);
            break;
        case 3:
            printf("\n请输入修改后的性别:");
            scanf("%s",This->sex);
            break;
        case 4:
            printf("\n请输入修改后的出生日期(月/日/年):");
            scanf("%d/%d/%d",&This->birthday.day,&This->birthday.month,&This->birthday.year);
            break;
        case 5:
            printf("\n请输入修改后的入学日期(月/日/年):");
            scanf("%d/%d/%d",&This->starttime.day,&This->starttime.month,&This->starttime.year);
            break;
        case 6:
            printf("\n请输入修改后的籍贯:");
            scanf("%s",This->addr);
            break;
        case 7:
            printf("\n请输入修改后的系别:");
            scanf("%s",This->department);
            break;
        case 8:
            printf("\n请输入修改后的专业:");
            scanf("%s",This->major);
            break;
        case 9:
            printf("\n请输入修改后的班级:");
            scanf("%s",This->clas);
            break;
        }
        printf("已成功修改该学生的信息.");
    }
    printf("\n按任意键返回主目录!");
    getchar();
    getchar();
}
//删除函数
void del(struct stud *pp)
{
    int m;struct stud *p=pp,*This=pp;char choice;
    printf("\n请输入您要删除的学生的学号:");
    scanf("%d",&m);
    while(This!=NULL)                                           //查找相应学号的学生
    {
        if(m==This->num)
            break;
        p=This;
        This=This->next;
    }
    if(This==NULL)
        printf("\n没有找到该学生的信息!");
    else
    {
        printf("\n已找到该学生的信息:");
        Print(This);
        printf("\n您确实要删除该学生的信息吗(Y/N)?");                //用户确认操作
        scanf("%c",&choice);
        while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')
        {
            printf("\n您的输入有误,请重新确认:");
            scanf("%c",&choice);
        }
        if(choice=='Y'||choice=='y')                           //删除该学生对应的结点
        {
            if(p==This)
            {
                Head=This->next;
                free(This);
            }
            else
            {
                p->next=This->next;
                free(This);
            }
            printf("\n已成功删除该信息!");
        }
    }
    printf("\n按任意键返回主目录!");
    getchar();
    getchar();
}
//统计函数
void statistic(struct stud *p)
{
    int x,i;
    union                                                     //定义一个共用体变量
    {
        struct Date a;
        char b[25];
    }temp;
    struct stud *This=NULL,*Next=NULL;                       //打印统计项目菜单
    printf("\n\t==================学生证管理系统==================\n");
    printf("\n\t***************************统计****************************\n");
    printf("\t***                                        ***\n");
    printf("\t***      1--性别         2--出生日期      ***\n");
    printf("\t***                                        ***\n");
    printf("\t***      3--入学日期     4--籍贯          ***\n");
    printf("\t***                                       ***\n");
    printf("\t***      5--系别         6--专业           ***\n");
    printf("\t***                                       ***\n");
    printf("\t***      7--班级         0--返回           ***\n");
    printf("\t***                                       ***\n");
    printf("\t*************************************************************\n");
    printf("\t\t请选择您要统计的项目:");
    scanf("%d",&x);
    while(x<0||x>7)                                      //保证用户正确操作
    {
        printf("\n您的输入有误,请重新选择:");
        scanf("%d",&x);
    }
    switch(x)                                           //选择相应的统计项目
    {
    case 1:
        printf("\n请输入您要统计的性别:");
        scanf("%s",&temp.b);
        This=Next=p;i=0;
        while(Next!=NULL)                               //打印并统计相应性别的人数
        {
            if(strcmp(Next->sex,temp.b)==0)
            {
                i++;
                Print(Next);
            }
            Next=Next->next;
        }
        printf("\n*************************************************\n");
        printf("\n性别为%s的学生共有%d人,具体成员如上.",temp.b,i);
        break;
    case 2:
        printf("\n请您要输入统计的出生日期(月/日/年):");
        scanf("%d/%d/%d",&temp.a.month,&temp.a.day,&temp.a.year);
        This=Next=p;i=0;
        while(Next!=NULL)                             //打印并统计相应出生日期的人数
        {
            if(Next->birthday.month==tepm.a.month&&Next->birthday.day==temp.a.day&&\Next->birthday.year==temp.a.year)
            {
                i++;
                Print(Next);
            }
            Next=Next->next;
        }
        printf("\n*************************************************\n");
        printf("\n出生日期为%2.2d/%2.2d/%4.4d的学生共有%d人,具体成员如上.",temp.a.month,temp.a.day,temp.a.year,i);
        break;
    case 3:
        printf("\n请您要输入统计的入学日期(月/日/年):");
        scanf("%d/%d/%d",&temp.a.month,&temp.a.day,&temp.a.year);
        This=Next=p;i=0;
        while(Next!=NULL)                       //打印并统计相应入学日期的人数
        {
            if(Next->starttime.month==temp.a.month&&Next->starttime.day==temp.a.day&&\
                Next->starttime.year==temp.a.year)
            {
                i++;
                Print(Next);
            }
            Next=Next->next;
        }
        printf("\n*************************************************\n");
        printf("\n入学日期为%2.2d/%2.2d/%4.4d的学生共有%d人,具体成员如上.",temp.a.month,temp.a.day,temp.a.year,i);
        break;
    case 4:
        printf("\n请输入您要统计的籍贯:");
        scanf("%s",&temp.b);
        This=Next=p;i=0;
        while(Next!=NULL)                           //打印并统计相应籍贯的人数
        {
            if(strcmp(Next->addr,temp.b)==0)
            {
                i++;
                Print(Next);
            }
            Next=Next->next;
            }
            printf("\n*************************************************\n");
            printf("\n籍贯为%s的学生共有%d人,具体成员如上.",temp.b,i);
            break;
    case 5:
        printf("\n请输入您要统计的系别:");
        scanf("%s",&temp.b);
        This=Next=p;i=0;
        while(Next!=NULL)                             //打印并统计相应系别的人数
        {
            if(strcmp(Next->department,temp.b)==0)
            {
                i++;
                Print(Next);
            }
            Next=Next->next;
        }
        printf("\n*************************************************\n");
        printf("\n系别为%s的学生共有%d人,具体成员如上.",temp.b,i);
        break;
    case 6:
        printf("\n请输入您要统计的专业:");
        scanf("%s",&temp.b);
        This=Next=p;i=0;
        while(Next!=NULL)                             //打印并统计相应专业的人数
        {
            if(strcmp(Next->major,temp.b)==0)
            {
                i++;
                Print(Next);
            }
            Next=Next->next;
        }
        printf("\n*************************************************\n");
        printf("\n专业为%s的学生共有%d人,具体成员如上.",temp.b,i);
        break;
    case 7:
        printf("\n请输入您要统计的班级:");
        scanf("%s",&temp.b);
        This=Next=p;i=0;
        while(Next!=NULL)                         //打印并统计相应班级的人数
        {
            if(strcmp(Next->clas,temp.b)==0)
            {
                i++;
                Print(Next);
                Next=Next->next;
            }
            printf("\n*************************************************\n");
            printf("\n班级为%s的学生共有%d人,具体成员如上.",temp.b,i);
            break;
    case 0:
        break;
        }
        printf("\n按任意键返回主目录!");
        getchar();
        getchar();
}
//打印函数
void Print(struct stud *student)                         //打印单个学生的详细信息
{
    printf("\n*************************************************\n");
    printf("Number:%d\n",student->num);
    printf("Name:%s\n",student->name);
    printf("Sex:%s\n",student->sex);
    printf("Birthday(month/day/year):%2.2d/%2.2d/%4.4d\n",student->birthday.month,student->birthday.day,\student->birthday.year);
    printf("Starttime(month/day/year):%2.2d/%2.2d/%4.4d\n",student->starttime.month,student->starttime.day,\student->starttime.year);
    printf("Address:%s\n",student->addr);
    printf("Department:%s\n",student->department);
    printf("Major:%s\n",student->major);
    printf("Class:%s\n",student->clas);
}
搜索更多相关主题的帖子: department include search modify C语言 
2013-06-20 11:03
我叫沃恩
Rank: 12Rank: 12Rank: 12
来 自:Asia
等 级:贵宾
威 望:10
帖 子:1234
专家分:3865
注 册:2013-3-29
收藏
得分:5 
自己调试吧!现在是考试时间,大家都比较忙,,,,

因为我是菜鸟,所以应该被骂! 细节+坚持=成功!
2013-06-20 11:38
YJ_Hao
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:215
专家分:609
注 册:2013-3-22
收藏
得分:5 
自己找找,多了几个\,少了一个}!!!


    case 7:
        printf("\n请输入您要统计的班级:");
        scanf("%s",&temp.b);
        This=Next=p;i=0;
        while(Next!=NULL)                         //打印并统计相应班级的人数
        {
            if(strcmp(Next->clas,temp.b)==0)
            {
                i++;
                Print(Next);          <-------------后面有个}才对!!!!
                Next=Next->next;
            }
            printf("\n*************************************************\n");
            printf("\n班级为%s的学生共有%d人,具体成员如上.",temp.b,i);
            break;


[ 本帖最后由 YJ_Hao 于 2013-6-20 12:23 编辑 ]
2013-06-20 12:21
enenenxixi
Rank: 1
等 级:新手上路
帖 子:5
专家分:5
注 册:2013-6-20
收藏
得分:5 
不明觉厉

...........................
2013-06-20 12:27
lzj12530
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:264
专家分:841
注 册:2013-3-28
收藏
得分:5 
首先你的函数声明用到结构体,那么结构体就必须在声明前进行定义

C++菜鸟
2013-06-20 12:28
lzj12530
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:264
专家分:841
注 册:2013-3-28
收藏
得分:0 
             if(Next->birthday.month==tepm.a.month&&Next->bir //temp书写错误

C++菜鸟
2013-06-20 12:28
lzj12530
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:264
专家分:841
注 册:2013-3-28
收藏
得分:0 
    if(Next->birthday.month==temp.a.month&&Next->birthday.day==temp.a.day&&\Next->birthday.year==temp.a.year) //这一个\ 字符应该是错误的吧

[ 本帖最后由 lzj12530 于 2013-6-20 12:32 编辑 ]

C++菜鸟
2013-06-20 12:30
YJ_Hao
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:215
专家分:609
注 册:2013-3-22
收藏
得分:0 
还有输入时的定义.日和月互换了~
2013-06-20 12:35
快速回复:急需,求大神解救,改正C语言程序错误。
数据加载中...
 
   



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

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