C语言实现学生信息管理系统

实现代码:

#include<stdio.h>    
#include<stdlib.h>    
#include<string.h>    
#include<malloc.h>    
#define LEN sizeof(struct Student)      
struct Student          //学生信息的结构体声明    
{    
    unsigned int num;   //记录学号    
    char name[20];      //记录姓名   
    char age[5];         //记录年龄     
    char sex[10];       //记录性别    
    char born[20];      //记录出生年月      
    char poli[20];      //记录政治面貌    
    char local[20];     //记录籍贯  
    char addr[100];     //记录家庭住址      
    char phone[20];     //记录联络电话    
    char mail[20];      //记录邮箱    
    struct Student *next;   //指向下一个结构体的指针    
};      
struct Student *head = NULL;    
unsigned int kg = 0;      
//******************对各功能函数的声明***************************    

void show();                                                            //显示函数的声明    
struct Student *input();                                                //新建学生信息的声明    
struct Student *insert(struct Student *head,struct Student *stu);       //插入学生信息的声明    
struct Student *del(struct Student *head);                              //删除学生信息的声明    
void alter(struct Student *head);                                       //修改学生信息的声明    
void search(struct Student *head,unsigned int num);                     //查询学生信息的声明    
void print(struct Student *head,unsigned int num);                      //打印学生信息的声明    
//***************************************************************    
void show()    
{    
    int n,z = 1,k = 0;    
    char cho;    
    do    
    {    
        //***********显示提示信息**********       
        printf("   ************************学生信息管理系统***********************************\n");    
        printf("   *                                                                         *\n");    
        printf("   *                       1.添加学生信息                                    *\n");        //显示序号1的功能    
        printf("   *                       2.显示学生信息                                    *\n");        //显示序号2的功能    
        printf("   *                       3.查询学生信息                                    *\n");        //显示序号3的功能    
        printf("   *                       4.修改学生信息                                    *\n");        //显示序号4的功能
        printf("   *                       5.删除学生信息                                    *\n");        //显示序号4的功能     
        printf("   *                       6.退出系统                                        *\n");        //显示序号5的功能    
        printf("   ***************************************************************************\n");        
        printf("   请输入功能序号: ");             //提示用户输入    
        while(!scanf("%d",&n))                     //接受用户输入的功能序号,并且进行排错    
        {    
            printf("   输入序号有误,请重新输入: ");    
            fflush(stdin);    
        }    
        printf("\n");                               //输出回车    

        while((n <=0 || n > 7))                                       //对用户输入不能实现的功能序号进行处理    
        {    
            printf("   抱歉,没有此功能,请重新输入功能序号: ");      //提示用户所输入的功能序号系统不能进行处理    
            fflush(stdin);    
            while(!scanf("%d",&n))                                  //接收用户重新输入的功能序号    
            {    
                printf("   输入序号有误,请重新输入: ");    
                fflush(stdin);    
            }    
            printf("\n");                                           //输出回车    
        }    

        switch(n)                           //对用户信息进行功能函数的调用    
        {      
            case 1:    
            {    
                head = input();    
                k = 1;    
                system("pause");    
                break;    
            }       
            case 2:    
            {   if (head == NULL) k = 1;    
                print(head,0);    
                printf("   ");            

                system("pause");    
                break;    
            }    
            case 3:    
            {    
               if (head == NULL) k = 1;    
                search(head,0);    
                printf("   ");    
                system("pause");    
                break;      
            }    
            case 4:    
            {    
                alter(head);    
                break;    
            }
            case 5:    
            {    
                del(head);      
                break;    
            }       
            case 6:    
            {    
               printf("   ");    
                if (k == 1)                 //对于没有对数据进行存盘的情况进行对用户提示以确认是否退出    
                {    
                    printf("数据未保存,是否退出? Y.是 N.否 请选择: ");                        
                    fflush(stdin);    
                    cho = getchar();    
                    if (cho == 'y' || cho == 'Y')    
                    {    
                        z = 0;    
                        printf("   ");    
                    }    
                    else if (cho == 'n' || cho == 'N')     
                        {}    
                    else    
                    {    
                        printf("   无效输入\n   ");                         
                        system("pause");    
                    }    

                }    
                else    
                {    
                    z = 0;    
                }    
                break;    
            }    
            case 7:    
            {    
                k = 0;    

                break;    
            }       
        }    
    }while(z == 1);    
}      
//***************************************************************      
struct Student *input()    
{    
    struct Student *p1,*p2;    
    unsigned m,n,i;    
    FILE *read;    
    char filename[20];    
    head = NULL;      
    //要求用户选择录入学生信息的方式    
    printf("   请选择录入方式:\n");                        
    printf("   1.从当前窗口录入\n");    
    printf("   2.从已有的文件(txt文件)录入\n");    
    printf("   请选择: ");    
    while(!scanf("%u",&m))                      //排除输入错误的情况    
    {    
        printf("   输入序号有误,请重新输入: ");    
        fflush(stdin);    
    }      
    while(m < 1 || m > 2)                     //排除输入错误的情况    
    {    
        printf("   请重新选择选择录入方式:\n");    
        printf("   1.从当前界面录入\n");    
        printf("   2.从已有文件(txt文件)录入\n");    
        printf("   请选择:   ");    
        fflush(stdin);    
        while(!scanf("%d",&m))    
        {    
            printf("   输入序号有误,请重新输入: ");    
            fflush(stdin);    
        }    
        printf("\n");           
    }    

    if (m == 1)                             //当前窗口录入    
    {    
        printf("   请输入学生人数: ");         
        while (!scanf("%u",&n))             //接收录入学生信息的人数,并对输入有误的进行排除    
        {    
            printf("   输入有误,请重新输入学生人数: ");    
            fflush(stdin);    
        }    
        if (n == 0)                         //对录入人数为0的情况进行处理    
        {    
            printf("   学生个数为0人,建立失败\n   ");         
            return (head);    
        }    
        FILE *fpWrite=fopen("data.txt","w"); //将信息写入到data.txt文件中  
        head = p2 = p1 = (struct Student *) malloc (LEN); //开辟内存,用于生成链表                                     
        printf("   学生个数为:%u个,请按照以下顺序输入\n",n);                           //对学生总数的提示,并且提示每个学生信息的输入顺序    
        printf("   学号、姓名、年龄、性别、出生年月、政治面貌、籍贯、家庭住址、电话、E-mail\n"); //每个学生信息的输入顺序    
        for(i = 0; i < n; i++)    
        {    
            printf("   请输入第%u个学生信息!\n",i+1);                                    //提示接下来要输入第几个学生的信息    
            printf("   ");                                                              //格式调整,输出三个空格    
            fflush(stdin);    
            while(!scanf("%d %s %s %s %s %s %s %s %s %s",&p2->num,p2->name,p2->age,p2->sex,p2->born,p2->poli,p2->local,p2->addr,p2->phone,p2->mail))    
            {    
                printf("   输入有误,请重新输入该学生信息\n   ");    
                fflush(stdin);    
            }  
            fprintf(fpWrite,"%d %s %s %s %s %s %s %s %s %s \n",p2->num,p2->name,p2->age,p2->sex,p2->born,p2->poli,p2->local,p2->addr,p2->phone,p2->mail);//写入数据到data.txt中     
            if (n == 1)                                                                 //对录入人数为1时的情况进行处理    
            {    
                p2->next = NULL;                 
            }    
            else                                                                        //对录入人数大于1的情况进行录入,并在录入时进行排序,每录入一位学生信息就开辟一个内存空间,用于下一个学生的录入    
            {    
                head = insert(head,p2);    
                p2 = (struct Student *) malloc (LEN);    
            }      

        }
        printf("   所有数据已经输入到data.txt文件中\n");
        fclose(fpWrite);      
    }    
    else        //对文件录入的处理    
    {    
        printf("   请输入文件名(如student): ");    
        while(!scanf("%s",filename))                        //接收用户输入的文件名,并对其进行排错    
        {    
            printf("   输入文件名有误,请重新输入: ");    
            fflush(stdin);    
        }    
        strcat(filename,".txt");                            //合并后缀名    
        while((read = fopen(filename,"r")) == NULL)         //如果该文件成功打开就进行学生信息的录入,否则继续要求用户输入文件名    
        {    
            printf("   未找到此文件,请重新输入文件名: ");    
            scanf("%s",filename);    
            strcat(filename,".txt");    
        }    
        if (!fscanf(read,"%u",&n))                          //接收从文件中录入的学生人数并进行排错    
        {    
            printf("   文件数据有错,结束录入\n   ");    
            fclose(read);    
            fflush(stdin);    
            return head;    
        }    
        FILE *write=fopen("data.txt","w");  
           if(write==NULL)  
           {  
                return 0;  
           }   
        p2 = p1 = (struct Student *) malloc (LEN);          //开辟内存空间,创建链表    
        for(i = 0; i < n; i++)                               //循环录入每一个学生的信息    
        {    
            if(!(fscanf(read,"%d %s %s %s %s %s %s %s %s %s",&p2->num,p2->name,p2->sex,p2->born,p2->sex,p2->poli,p2->local,p2->addr,p2->phone,p2->mail)&&
            (fprintf(write,"%d %s %s %s %s %s %s %s %s %s",&p2->num,p2->name,p2->sex,p2->born,p2->sex,p2->poli,p2->local,p2->addr,p2->phone,p2->mail))))    
            //当遇到数据有误,释放内存空间,返回NULL    
            {    
                fclose(read);    
                p2 = head;    
                p1 = p2->next;    
                do                      //释放链表空间    
                {                           
                    free(p2);    
                    p2 = p1;                        
                    if (p1 != NULL)    
                        p1 = p1->next;    
                    else    
                        break;    
                }while(p2 != NULL);    
                printf("   数据有误,结束录入\n   ");    
                return NULL;        //返回NULL    
            }    
            if (n == 1)             //对录入人数为1的情况进行处理    
            {    
                p2->next = NULL;    
            }    
            else                    //对录入人数大于1的情况进行录入,并在录入时进行排序,开辟内存空间用于下一个学生信息的录入    
            {    
                head = insert(head,p2);    
                p2 = (struct Student *) malloc (LEN);    
            }    
        }    
        fclose(read);               //关闭文件    
    }      
    printf("   成功录入学生信息,并且学生信息已经按学号从小到大排列\n");    
    return head;                    //返回*head指针的地址    
}    

struct Student *insert(struct Student *head,struct Student *stu)        //插入学生信息功能函数定义    
{    
    struct Student *p1,*p2;    
    if (stu == NULL)            //对于传入插入学生信息为空时要求用户输入插入的学生信息    
    {       
        printf("   请按照学号、姓名、年龄、性别、出生年月、政治面貌、籍贯、家庭住址、电话、E-mail输入\n   ");  //每个学生信息的输入顺序    
        stu = (struct Student *) malloc (LEN);    
        while(!scanf("%d %s %s %s %s %s %s %s %s %s",&stu->num,&stu->name,stu->age,stu->sex,stu->born,stu->poli,stu->local,stu->addr,stu->phone,stu->mail))    
        {    
            printf("   输入信息有误,请重新输入\n");    
            fflush(stdin);    
        }    
    }    
    if (head == NULL)           //对于链表为空的情况的处理    
    {    
        head = stu;    
        head->next = NULL;    
    }    
    else                        //在链表中插入学生信息    
    {    
        p1 = p2 = head;    
        while(stu->num > p2->num && p1->next != NULL)       //查找适合位置的前一个学生    
        {    
            p2 = p1;    
            p1 = p1->next;    
        }    
        if (p2 == p1)           //插入的学生正好为链表头的情况    
        {    
            if (stu->num < p2->num)            //插入在表头前    
            {    
                head = stu;    
                stu->next = p2;    
            }    
            else                            //插入在表头后    
            {    
                p2->next = stu;    
                stu->next = NULL;    
            }    
        }    
        else                    //插入的学生在链表中的情况    
        {    
            if (stu->num < p1->num)            //插入到p1指向的学生前    
            {    
                p2->next = stu;    
                stu->next= p1;    
            }    
            else                            //插入到p1指向的学生后    
            {    
                p1->next = stu;    
                stu->next =  NULL;    
            }    
        }    
    }    
    kg = 1;    
    return(head);    
}      
struct Student *del(struct Student *head)               //删除学生信息的功能函数定义    
{    
    unsigned int num,k;    
    struct Student *p1,*p2;    
    if (head == NULL)                                   //对空链表删除的情况处理    
    {    
        printf("   没有学生信息,结束删除\n");         
        return(head);    
    }    
    printf("   请输入要删除的学生学号: ");             //求用户输入要删除的学生学号    
    while(!scanf("%u",&num))                            //接收学生序号并进行排错处理    
    {    
        printf("   输入有误,请重新输入学生序号: ");    
        fflush(stdin);    
    }    
    do    
    {    
        p1 = p2 = head;    
        while(num != p1->num && p1->next != NULL)     //查找删除位置的前一个学生    
        {    
            p2 =p1;    
            p1= p1->next;    
        }    
        if (num == p1->num)                              //对满足要求的学生进行删除    
        {    
            if (num == p1->num)    
            {    
                if (p1->next == NULL && p1 == head)      //对只有一个节点的链表进行删除    
                {    
                    free(p1);    
                    head = NULL;    
                }    
                else if (p1->next == NULL)               //删除链表尾节点    
                {    
                    free(p1);    
                    p2->next = NULL;    
                }    
                else if (head == p1)                    //删除表头节点    
                {    
                    head = p1->next;    
                    free(p1);    
                }    
                else                                    //删除表中节点    
                {    
                    p2->next = p1->next;    
                    free(p1);    
                }    
            }    
            printf("   成功删除学生信息\n");            //提示删除成功信息    
        }    
        else                                            //找不到要删除的学生时的提示    
        {    
            printf("   找不到该同学信息\n");    
            fflush(stdin);    
        }    
        if (head == NULL)                               //对空链表删除时的处理    
        {    
            printf("   没有学生信息,结束删除\n");         
            return(head);    
        }    
        else                                            //提示用户删除后是否继续    
        {    
            printf("   1.继续删除学生信息\n");    
            printf("   2.结束删除\n");    
            printf("   请选择: ");    
            while(!scanf("%u",&k))                      //接收用户选择    
            {    
                printf("   输入有误,请重新输入选择的序号: ");    
                fflush(stdin);    
            }    
            if (k == 1)                                 //选择继续    
            {    
                printf("   请输入要删除的学生学号: ");    
                while(!scanf("%u",&num))    
                {    
                    printf("   输入有误,请重新输入学生学号: ");    
                    fflush(stdin);    
                }    
            }    
            else if (k != 2)                            //对于不是选择2的继续循环提示    
            {    
                k = 1;    
            }    
        }    
    }while(k == 1);     
    return(head);       //返回表头地址    
}    

void search(struct Student *head,unsigned int num)      //查询函数的定义    
{    
    unsigned int cho,t = 0;  
    struct Student *p1,*p2;    

    if (head == NULL)       //对查询空链表时的操作    
    {    
        printf("   没有学生信息,结束查询\n");         
        return;    
    }    
    p1 = head;    
    if (num == 0)           //当传入实参 num = 0 需要接受用户需要的查询方式(个别或者全部),不等于0则可以直接查询个别学生信息    
    {    
        printf("   1.按学号查询学生信息\n");    
        printf("   2.按姓名查询学生信息\n");    
        printf("   请选择: ");    
        while(!scanf("%u",&cho))    //对错误输入数据的处理    
        {    
            printf("   输入有误,请重新输入序号: ");    
            fflush(stdin);    
        }    
        while(cho != 1 && cho != 2)                                                     //处理不能处理的功能序号                                                   
        {    
            printf("   抱歉,没有此功能,请重新输入功能序号: ");              //提示不能处理的信息,并要求用户重新输入功能序号    
            while(!scanf("%u",&cho))                                                        //接收用户重新输入的功能序号    
            {    
                printf("   输入序号有误,请重新输入序号: ");    
                fflush(stdin);    
            }    
            printf("\n");                                                       //输出回车    
        }    
    }    
    else    
    {    
        cho = 1;         //设置直接查询个别学生的开关    
    }    
    if (kg == 1)        //kg(全局变量)为全部学生查询的开关  kg = 1 打开开关由下面直接进行全部学生查询 kg = 0 关闭开关    
    {    
        cho = 2;    
    }    
    switch(cho) //查询类别分支    
    {    
        case 1: //查询个别学生    
        {    
            do    
            {    
                p1 = head;    
                if (num == 0 || t == 1)     
                {    
                    printf("   请输入需要查询的学生学号: ");    
                    while(!scanf("%u",&num))    
                    {    
                        printf("   输入有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                    t = 1;  //打开开关,该开关为查询完毕后 num不能作为该分支的条件(因为以下的操作会改变num的值)而建立的,并且能够实现当传入num不等于0时,以下询问用户是否继续的分支就不用执行了    
                }    
                else    
                {    
                    cho = 2; //如果传入的实参num不等于0  则该 DO WHILE 循环只做一次    
                }    
                while(p1->num != num)    //查找查询学生学号    
                {    
                    if (p1->next == NULL) break;   
                    p1 = p1->next;    
                }    
                if (p1->num == num)  //查找成功一表格方式输出该学生信息    
                { // printf("p1-num=%d\n",p1->num);printf("num=%d\n",num);  
                    //***********************表格头部设计************************    
                    printf("┏ ━━┳━━━┳━━┳━━┳━━━━┳━━━━┳━━━┳━━━━┳━━┳━━┓\n");    
                    printf("┃学号 ┃姓名  ┃年龄┃性别┃出生年月┃政治面貌┃籍贯  ┃家庭住址┃电话┃邮箱┃\n");     
                    printf("┣ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");  
                    printf("┃%-4d┃%-6s┃%-3s ┃%-4s┃%-5s  ┃%-8s┃%-8s┃%-6s┃%-4s┃%-4s┃\n",p1->num,p1->name,p1->age,p1->sex,p1->born,p1->poli,p1->local,p1->addr,p1->phone,p1->mail);    
                    //*********************************************************    
                }    
                else //查找不成功,提示用户找不到该学生    
                {    
                    printf("   找不到该学生\n");    
                }    
                if (t == 1)  //如果传入的num=0,则此分支有效,询问用户是否继续查询    
                {    
                    printf("   1.继续查询\n");    
                    printf("   2.结束查询\n");    
                    printf("   请选择: ");    
                    while(!scanf("%u",&cho))  //对输入序号查错,利用cho = 2时的情况跳出  DO WHILE 循环    
                    {    
                        printf("   输入序号有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                }    
            }while (cho == 1);    
            break;    
        }    
        case 2: //按学生姓名查询信息    
        {  char name[20]="";   
            do    
            {    
                p2 = head;                  
                if (1)     
                {    
                    printf("   请输入需要查询的学生姓名: ");                      
                    while(!scanf("%s",&name))    
                    {    
                        printf("   输入有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                    t = 1;  //打开开关,该开关为查询完毕后 name不能作为该分支的条件(因为以下的操作会改变name的值)而建立的,并且能够实现当传入name不等于0时,以下询问用户是否继续的分支就不用执行了    
                }    
                else    
                {    
                    cho = 2; //如果传入的实参name不等于0  则该 DO WHILE 循环只做一次    
                }      
                // printf("p2-name1 = %s\n",p2->name); printf("name1=%s\n",name);  
                while(strcmp(p2->name,name)!= 0)    //查找查询学生学号    
                {   
                    if (p2->next == NULL) break; //printf("hello-2 ****");   
                    p2 = p2->next;    
                }    

                //printf("p2-name3 = %s\n",p2->name); printf("name4=%s\n",name);  
                if (strcmp(p2->name,name)==0)  //查找成功一表格方式输出该学生信息    
                {    
                    //***********************表格头部设计************************    
                    printf("┏ ━━┳━━━┳━━┳━━┳━━━━┳━━━━┳━━━┳━━━━┳━━┳━━┓\n");    
                    printf("┃学号 ┃姓名  ┃年龄┃性别┃出生年月┃政治面貌┃籍贯  ┃家庭住址┃电话┃邮箱┃\n");     
                    printf("┣ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");  
                    printf("┃%-4d┃%-6s┃%-3s ┃%-4s┃%-5s  ┃%-8s┃%-8s┃%-6s┃%-4s┃%-4s┃\n",p2->num,p2->name,p2->age,p2->sex,p2->born,p2->poli,p2->local,p2->addr,p2->phone,p2->mail);    
                    //*********************************************************    
                    break;  
                }    
                else //查找不成功,提示用户找不到该学生    
                {    
                    printf("   找不到该学生\n");    
                }  

                if (t == 1)  //如果传入的name,则此分支有效,询问用户是否继续查询    
                {    
                    printf("   1.继续查询\n");    
                    printf("   2.结束查询\n");    
                    printf("   请选择: ");    
                    while(!scanf("%u",&cho))  //对输入序号查错,利用cho = 2时的情况跳出  DO WHILE 循环    
                    {    
                        printf("   输入序号有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                }    
            }while (cho == 1);    
            break;   

        }    
    }    
    if (kg == 1) kg = 0; //关闭查询全部学生的开关,以便下一次使用    
}    

void print(struct Student *head,unsigned int num)      //打印函数的定义    
{    
    unsigned int cho,t = 0;    
    struct Student *p1;    
    if (head == NULL)       //对打印空链表时的操作    
    {     return;    
    }    
    p1 = head;    
    if (num == 0)           //当传入实参 num = 0 需要直接打印学生信息    
    {   cho=2;  
        }    
    else    
    {    cho = 1;         //设置直接查询个别学生的开关    
    }    
    if (kg == 1)        //kg(全局变量)为全部学生查询的开关  kg = 1 打开开关由下面直接进行全部学生查询 kg = 0 关闭开关    
    {   cho = 2;    
    }    
    switch(cho) //打印   
    {    
        case 1:    
        {     break;    
        }    
        case 2: //打印全部信息    
        {    
            //***********************表格头部设计************************    
                printf("┏ ━━┳━━━┳━━┳━━┳━━━━┳━━━━┳━━━┳━━━━┳━━┳━━┓\n");   
                printf("┃学号 ┃姓名  ┃年龄┃性别┃出生年月┃政治面貌┃籍贯  ┃家庭住址┃电话┃邮箱┃\n");     
                printf("┗ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");   
            //****************表格主体设计以及数据输出******************    
            while(p1 != NULL)    
            {     
                printf("┣ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n");    
                printf("┃%-4d┃%-6s┃%-3s ┃%-4s┃%-5s  ┃%-8s┃%-8s┃%-6s┃%-4s┃%-4s┃\n",p1->num,p1->name,p1->age,p1->sex,p1->born,p1->poli,p1->local,p1->addr,p1->phone,p1->mail);    
                p1 = p1->next;     
            }    
                printf("┗ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");    
            break;    
        }    
    }    
    if (kg == 1) kg = 0; //关闭打印全部学生的开关,以便下一次使用    
}    

void alter(struct Student *head)  //修改学生信息的功能函数定义    
{    
    struct Student *p1,*p2;    
    unsigned int num,cho,k,l=0;    
    if (head == NULL)   //对空链表的处理    
    {    
        printf("   没有学生信息,结束修改\n   ");    
        system("pause");    
        return;    
    }    
    printf("   请输入需要修改的学生学号: ");    
    while(!scanf("%u",&num))    //接受用户输入的学号并且进行查错    
    {    
        printf("   输入学号有误,请重新输入: ");    
        fflush(stdin);    
    }    
    do    
    {    
        p2 = p1 = head;    
        while(p1->num != num)    //查找学生学号    
        {    
            if (p1->next == NULL)    
                break;    
            p2 = p1;    
            p1 = p1->next;    
        }    
        if (p1->num == num)      //查找成功    
        {    
            printf("   已找到该学生,该学生的信息为: \n");    
            search(head,num);    
            l = 0;    
            do    
            {    
                if (l == 0)     //开关,当第一次循环时 l=0 执行 IF 语句    
                    printf("   选择修改的内容\n");    
                else        
                    printf("   序号输入错误,请重新选择\n");    
                l = 1;  //打开开关,以在以下操作用户输入序号超出范围时控制上面的分支语句,进而可以更好地向用户提示信息    
                printf("   1.学号\n");    
                printf("   2.姓名\n");    
                printf("   3.年龄\n");    
                printf("   4.性别\n");    
                printf("   5.出生年月\n");    
                printf("   6.政治面貌\n");    
                printf("   7.籍贯\n");    
                printf("   8.家庭住址\n");    
                printf("   9.全部\n");    
                printf("   请选择序号: ");    
                fflush(stdin);    
                while(!scanf("%u",&cho)) //接受序号并查错    
                {    
                    printf("   输入序号有误,请重新输入: ");    
                    fflush(stdin);    
                }    
            }while(cho > 9 || cho < 1);    
            switch(cho)  //对序号进行多分支处理    
            {    
                case 1:    
                {    
                    printf("   请输入该学生改正的学号信息: ");    
                    while(!scanf("%u",&p1->num))    
                    {    
                        printf("   输入改正信息有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                    break;    
                }    
                case 2:    
                {    
                    printf("   请输入该学生改正的姓名信息: ");    
                    while(!scanf("%s",p1->name))    
                    {    
                        printf("   输入改正信息有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                    break;    
                }    
                case 3:    
                {    
                    printf("   请输入该学生改正的年龄信息: ");    
                    while(!scanf("%s",p1->age))    
                    {    
                        printf("   输入改正信息有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                    break;    
                }    
                case 4:    
                {    
                    printf("   请输入该学生改正的性别信息: ");    
                    while(!scanf("%s",p1->sex))    
                    {    
                        printf("   输入改正信息有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                    break;    
                }    
                case 5:    
                {    
                    printf("   请输入该学生改正的出生年月信息: ");    
                    while(!scanf("%s",p1->born))    
                    {    
                        printf("   输入改正信息有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                    break;    
                }    
                case 6:    
                {    
                    printf("   请输入该学生改正的政治面貌信息: ");    
                    while(!scanf("%s",p1->poli))    
                    {    
                        printf("   输入改正信息有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                    break;    
                }    
                case 7:    
                {    
                    printf("   请输入该学生改正的籍贯信息: ");    
                    while(!scanf("%s",p1->local))    
                    {    
                        printf("   输入改正信息有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                    break;    
                }    
                case 8:    
                {    
                    printf("   请输入该学生改正的家庭住址信息: ");    
                    while(!scanf("%s",p1->addr))    
                    {    
                        printf("   输入改正信息有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                    break;    
                }    
                case 9:    
                {    
                    printf("   请输入该学生全部要改正的所有信息: ");    
                    while(!scanf("%u %s %s %s %s %s %s %s %s %s",&p1->num,p1->name,p1->age,p1->sex,p1->born,p1->poli,p1->local,p1->addr,p1->phone,p1->mail))    
                    {  //%u %s %s %s %s %s %s %s",&p1->num,p1->grade,p1->name,p1->born,p1->sex,p1->poli,p1->phone,p1->addr  
                        printf("   输入改正信息有误,请重新输入: ");    
                        fflush(stdin);    
                    }    
                    break;    
                }    
            }    
            if (cho == 1 || cho == 9)   //对修改过学号的学生进行重新排序    
            {    
                if (p1 == head) //当该学生在链表头时,删除链表头节点    
                {    
                    head = head->next;    
                }    
                else if (p1->next == NULL) //当该学生在链表尾时,删除链表尾节点    
                {    
                    p2->next = NULL;    
                }    
                else    //当该学生在链表中时,删除该学生对应的节点    
                {    
                    p2->next = p1->next;    
                }    
                head = insert(head,p1); //利用插入学生信息功能函数,进行该学生的重新排序    
            }    
            printf("   修改成功,该学生改正后的信息为: \n");    
            search(head,p1->num);    //显示以下修改后的学生信息    

            //询问用户是否继续    
            printf("   1.继续修改其他学生信息\n");    
            printf("   2.退出修改\n");    
            printf("   请选择: ");    
            while(!scanf("%u",&k))      //接受用户输入的序号,并进行排错    
            {    
                printf("   输入序号有误,请重新输入: ");    
                fflush(stdin);    
            }    
            if (k == 1) //接受下一次修改的学生学号    
            {    
                printf("   请输入需要修改的学生学号: ");    
                while(!scanf("%u",&num))    
                {    
                    printf("   输入修改信息有误,请重新输入: ");    
                    fflush(stdin);    
                }    
            }    
            else if (k != 2) //排错    
            {    
                printf("   输入有误,请重新输入\n");    
            }    
        }    
        else    //查找不到学生时要求用户进行重新输入学生序号    
        {       
            k = 1;    
            printf("   找不到该学生信息,请重新输入需要修改的学生学号: ");    
            fflush(stdin);    
            while(!scanf("%u",&num));  //接受用户重新输入的学号并进行排错    
            {    
                printf("   输入修改信息有误,请重新输入: ");    
                fflush(stdin);    
            }    
        }    
    }while(k == 1);    
    printf("   ");    
    system("pause");    
}    


int  main()    
{       
    show();  
    return 0;   //调用显示功能函数    
}  

初始页面:

这里写图片描述

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值