C语言实现学籍管理系统课程设计
作者:指关节
这篇文章主要为大家详细介绍了C语言实现学籍管理系统课程设计,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了C语言实现学籍管理系统的具体代码,供大家参考,具体内容如下
学校的课程设计,自己完成后整理了一下。
自己用链表实现的一个较简单的学籍管理系统,都是通过一些链表以及文件的基本操作完成。
功能实现
1-录入学生信息。
2-查询学生信息。
3-修改学生信息 。
4-删除学生信息。
5-显示学生信息。
6-统计信息报表。
7-读盘,存盘。
注:一些getchar()以及换行符是我为了让界面美观自己加的。
#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<ctype.h> #include<string.h> #include<windows.h> #define LEN sizeof(struct _stu) typedef struct _stu { long int id; //学号 char name[20]; //姓名 char sex[10]; //性别 char teacher[20]; //老师 int years; //年龄 char date[20]; //入学时间 float score; //入学成绩 struct _stu *next; //指向下个结点的指针 }Stu; int count = 0;//链表长度,学生总数 char choice_s;//选择 void Show();//登陆界面 void Menu();//显示主菜单 Stu *Insert(Stu *pHead);//录入 Stu *Find(Stu *pHead, int id); void Find_sum(Stu *pHead);//查询 void print(Stu *p);//显示 void Change(Stu *pHead, int id);//修改 Stu *Delete(Stu *pHead, int id);//删除 void printAll(Stu *pHead);//显示全部学生信息(总) void printAll_1(Stu *pHead);//显示全部学生信息(姓名升序) void printAll_2(Stu *pHead);//显示全部学生信息(成绩降序) void data_statistics(Stu *pHead);//数据统计,打印报表 Stu *read_file(Stu *pHead);//读盘 void DeleteLink(Stu *pHead);//销毁链表 void save_file(Stu *pHead);//存盘 int main() { SetConsoleTitle("西安邮电大学学籍管理系统"); //头文件<windows.h> int i = 0; long int id; Stu *pHead = NULL; system("color 5A"); //头文件<windows.h>,改变程序背景及字体颜色 Show(); pHead = read_file(pHead); while(1) { Menu(); switch(choice) { case '1': pHead = Insert(pHead); break; case '2': Find_sum(pHead); break; case '3': printf("\n\n"); printf("\t输入要修改学生学号: "); scanf("%ld",&id); Change(pHead,id); break; case '4': printf("\n\n"); printf("\t输入要删除学生学号: "); scanf("%ld",&id); pHead = Delete(pHead,id); break; case '5': printAll(pHead); break; case '6': data_statistics(pHead); break; case '7': printf("\n\n"); printf("\t学生总数为:%d\n",count); printf("\n"); printf("\t请按任意键继续..."); break; case '0': save_file(pHead); DeleteLink(pHead); //销毁链表 printf("\n\n\n"); printf("\t谢谢使用!\n"); exit(0); } } return 0; } void Show() //自己添加的登陆功能,比较简单,可以自己修改添加 { int i; char passwd[18]; char *ch = "WELCOME"; printf("\n\n\n"); printf("\t\t\t----------------------------------------------------------\n"); printf("\t\t\t| Welcome To The System |\n"); printf("\t\t\t----------------------------------------------------------\n"); printf("\t\t\t 用户名登陆:"); do { scanf("%s",passwd); if((strcmp(passwd,"1234567")) != 0) { printf("\a");//错误警示 printf("\n"); printf("\t\t\t 用户名错误,请重新输入:"); fflush(stdin); } }while((strcmp(passwd,"1234567")) != 0); for(i = 1; i <= 100; i++) { printf("\n\n\n\n\n\n\n\n\n"); printf("\t\t\t\t\t加载:%d%%",i); Sleep(9); //头文件<windows.h>,停顿9毫秒 system("cls"); //头文件<windows.h>,清屏 } printf("\n\n\n\n\n\n\n\n\n"); printf("\t\t\t\t\t加载完毕"); Sleep(666); system("cls"); printf("\n\n\n\n\n\n\n\n\n"); printf("\t\t\t\t\t"); for(i = 0; i < 7; i++) { printf("%c",ch[i]); Sleep(333); } printf("\n\n\n"); printf("\t\t\t\t\t\t\t请按任意键继续..."); } void Menu() //主菜单 { getch(); system("cls");//清屏 system("color 0D"); printf("\n\n"); printf("\t----------------------------------------------------------\n"); printf("\t| 欢迎使用学籍管理系统 |\n"); printf("\t----------------------------------------------------------\n"); printf("\t| 1-录入学生信息 |\n"); printf("\t----------------------------------------------------------\n"); printf("\t| 2-查询学生信息 |\n"); printf("\t----------------------------------------------------------\n"); printf("\t| 3-修改学生信息 |\n"); printf("\t----------------------------------------------------------\n"); printf("\t| 4-删除学生信息 |\n"); printf("\t----------------------------------------------------------\n"); printf("\t| 5-显示学生信息 |\n"); printf("\t----------------------------------------------------------\n"); printf("\t| 6-统计信息报表 |\n"); printf("\t----------------------------------------------------------\n"); printf("\t| 7-学生总数(.读盘) |\n"); printf("\t----------------------------------------------------------\n"); printf("\t| 0-退出程序(.存盘) |\n"); printf("\t----------------------------------------------------------\n"); printf("\t请选择功能(0-7): "); fflush(stdin); scanf("%c",&choice_s); if(choice_s < '0' || choice_s > '7') { printf("\t请重新选择功能(0-7): "); scanf("%c",&choice_s); } system("cls");//清屏 } Stu *Insert(Stu *pHead) //创建链表 { Stu *pEnd; Stu *pNew,*q; pNew = (Stu *)malloc(LEN); q = pHead; pEnd = pHead; printf("\n\n"); printf("\t---------------------------------------------------------\n"); printf("\t| ***录入学生信息*** |\n"); printf("\t---------------------------------------------------------\n"); printf("\t该学生的学号为: "); scanf("%ld",&pNew->id); while(pNew->id < 0) { printf("\t学号不能为负,请重新输入"); scanf("%ld",&pNew->id); } while(q) { if(q->id == pNew->id) { printf("\t学号已存在,请重新输入: "); scanf("%ld",&pNew->id); q = pHead; continue; } q = q->next; } printf("\t学生姓名: "); scanf("%s",pNew->name); printf("\t学生性别: "); scanf("%s",pNew->sex); printf("\t学生老师: "); scanf("%s",pNew->teacher); printf("\t学生年龄: "); scanf("%d",&pNew->years); while(pNew->years < 0) { printf("\t年龄不能为负,请重新输入:"); scanf("%d",&pNew->years); } printf("\t学生入学时间: "); scanf("%s",pNew->date); while(strlen(pNew->date) < 8) { printf("\t入学日期(年/月/日),请重新输入; "); scanf("%s",pNew->date); } printf("\t学生入学成绩: "); scanf("%f",&pNew->score); while(pNew->score < 0 || pNew->score > 750) { printf("\t入学成绩(0-750),请重新输入: "); scanf("%f",&pNew->score); } pNew->next = NULL; if(pHead == NULL) pHead = pNew; else { while(pEnd && pEnd->next != NULL) pEnd = pEnd->next; pEnd->next = pNew; } count++; printf("\n"); printf("\t请按任意键继续..."); return pHead; } void Find_sum(Stu *pHead) //4种查询方式 { char choice; long int id; float score; char teacher[20]; Stu *p = pHead; printf("\n\n"); printf("\t---------------------------------------------------------\n"); printf("\t| ***查询学生信息*** |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 1.按学号查询 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 2.按成绩查询 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 3.按老师和学号查询 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 4.按老师和成绩查询 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 0.返回主菜单 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t请选择查询方式: "); fflush(stdin); scanf("%c",&choice); while(choice < '0' || choice > '4') { printf("\t请重新选择功能(0-4): "); fflush(stdin); scanf("%c",&choice); } switch(choice) { case '1': printf("\t输入要查询学生学号: "); scanf("%ld",&id); print(Find(pHead,id)); //调用print(),Find()函数 printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '2': printf("\t输入要查询学生成绩: "); scanf("%f",&score); while(p && p->score != score) p = p->next; if(!p) { printf("\t对不起,没有查询到该学生信息.\n"); } else { printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t---------------------------------------------------------\n"); while(p) { if(p->score == score) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",p->id,p->name,p->sex,p->teacher,p->years,p->date,p->score); p = p->next; } else p = p->next; } } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '3': printf("\t输入要查询老师和其学生学号: "); scanf("%s %ld",teacher,&id); while(p && strcmp(p->teacher,teacher) != 0 && p->id != id) p = p->next; if(!p) { printf("\t对不起,没有查询到该信息.\n"); } else { printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t---------------------------------------------------------\n"); while(p) { if(strcmp(p->teacher,teacher) == 0 && p->id == id) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",p->id,p->name,p->sex,p->teacher,p->years,p->date,p->score); p = p->next; } else p = p->next; } } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '4': printf("\t输入要查询老师和其学生成绩: "); scanf("%s %f",teacher,&score); while(p && strcmp(p->teacher,teacher) != 0 && p->score != score) p = p->next; if(!p) { printf("\t对不起,没有查询到该信息.\n"); } else { printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t---------------------------------------------------------\n"); while(p) { if(strcmp(p->teacher,teacher) == 0 && p->score == score) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",p->id,p->name,p->sex,p->teacher,p->years,p->date,p->score); p = p->next; } else p = p->next; } } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '0': return; } } Stu *Find(Stu *pHead, int id) { Stu *p = pHead; while(p && p->id != id) p = p->next; return p; } void print(Stu *p) { if(!p) { printf("\t对不起,没有查询到该学生信息.\n"); } else { printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t---------------------------------------------------------\n"); getchar(); printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",p->id,p->name,p->sex,p->teacher,p->years,p->date,p->score); } } void Change(Stu *pHead, int id) { Stu *pNew = Find(pHead,id); 调用Find()函数 Stu *q = pHead; char choice; int num; int flag = 0; if(pNew) { printf("\n\n"); printf("\t---------------------------------------------------------\n"); printf("\t| ***修改学生信息*** |\n"); printf("\t---------------------------------------------------------\n"); printf("\t该学生信息如下: \n"); printf("\t---------------------------------------------------------\n"); print(pNew); //调用print()函数 printf("\t---------------------------------------------------------\n"); printf("\t1.学号\t2.姓名3.性别\t4.老师\t5.年龄\n"); printf("\t6.入学时间\t7.入学成绩\t8.全部修改\t0.返回主菜单\n"); printf("\t请选择修改类型: "); fflush(stdin); scanf("%c",&choice); while(choice < '0' || choice > '8') { printf("\t请重新选择功能(0-8): "); fflush(stdin); scanf("%c",&choice); } switch(choice) { case '1': printf("\t请输入新的学号: "); scanf("%ld",&pNew->id); while(pNew->id < 0) { printf("\t学号不能为负,请重新输入: "); scanf("%ld",&pNew->id); } num = pNew->id; while(q) { if(q->id == num) flag++; q = q->next; } if(flag > 1) { printf("\t学号已存在,请重新选择!\n"); //学号已存在,直接返回主菜单 printf("\n"); printf("\t请按任意键继续..."); return; } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '2': printf("\t请输入新的学生姓名: "); scanf("%s",pNew->name); printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '3': printf("\t请输入新的学生性别: "); scanf("%s",pNew->sex); printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '4': printf("\t请输入新的学生老师: "); scanf("%s",pNew->teacher); printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '5': printf("\t请输入新的学生年龄: "); scanf("%d",&pNew->years); while(pNew->years < 0) { printf("\t年龄不能为负,请重新输入:"); scanf("%d",&pNew->years); } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '6': printf("\t请输入新的入学时间: "); scanf("%s",pNew->date); while(strlen(pNew->date) < 8) { printf("\t入学日期(年/月/日),请重新输入; "); scanf("%s",pNew->date); } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '7': printf("\t请输入新的入学成绩: "); scanf("%f",&pNew->score); while(pNew->score < 0 || pNew->score > 750) { printf("\t入学成绩(0-750),请重新输入: "); scanf("%f",&pNew->score); } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '8': printf("\t学号: "); scanf("%ld",&pNew->id); while(pNew->id < 0) { printf("\t学号不能为负,请重新输入: "); scanf("%ld",&pNew->id); } num = pNew->id; while(q) { if(q->id == num) flag++; q = q->next; } if(flag > 1) { printf("\t学号已存在,请重新选择!"); printf("\n"); printf("\t请按任意键继续..."); return; } printf("\t学生名称: "); scanf("%s",pNew->name); printf("\t学生性别: "); scanf("%s",pNew->sex); printf("\t老师: "); scanf("%s",pNew->teacher); printf("\t年龄: "); scanf("%d",&pNew->years); while(pNew->years < 0) { printf("\t年龄不能为负,请重新输入:"); scanf("%d",&pNew->years); } printf("\t入学时间: "); scanf("%s",pNew->date); while(strlen(pNew->date) < 8) { printf("\t入学日期(年/月/日),请重新输入; "); scanf("%s",pNew->date); } printf("\t入学成绩: "); scanf("%f",&pNew->score); while(pNew->score < 0 || pNew->score > 750) { printf("\t入学成绩(0-750),请重新输入: "); scanf("%f",&pNew->score); } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '0': printf("\n"); printf("\t请按任意键继续..."); return; } } else { printf("\t对不起,没有查询到该学生信息.\n"); printf("\n"); printf("\t请按任意键继续..."); getchar(); } } Stu *Delete(Stu *pHead, int id) { Stu *pNew = Find(pHead,id); //调用Find()函数 Stu *pTemp,*q; char ch; pTemp = pHead; q = pTemp; if(pTemp == NULL) { printf("\t暂无学生信息,请先添加!"); printf("\n"); printf("\t请按任意键继续..."); getchar(); return pHead; } if(pNew) { print(pNew); printf("\t是否删除(y/n): "); scanf("%c",&ch); count--; switch(ch) { case 'y': while(pTemp) { if(pTemp->id == id) { if(pHead == pTemp) //特殊情况,删除头节点 { pHead = pTemp->next; printf("\n"); printf("\t请按任意键继续..."); return pHead; } q->next = pTemp->next; free(pTemp); printf("\n"); printf("\t请按任意键继续..."); return pHead; } q = pTemp; pTemp = pTemp->next; } case 'n': return pHead; } } else { printf("\t对不起,没有查询到该学生信息.\n"); printf("\n"); printf("\t请按任意键继续..."); getchar(); return pHead; } } void printAll(Stu *pHead) //3种显示方式,通过冒泡排序 { char choice; Stu *pNew = pHead; printf("\n\n"); printf("\t---------------------------------------------------------\n"); printf("\t| ***显示学生信息*** |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 1.按学号升序显示 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 2.按姓名升序显示 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 3.按成绩降序显示 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 0.返回主菜单 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t请选择显示方式: "); fflush(stdin); scanf("%c",&choice); while(choice < '0' || choice > '3') { printf("\t请重新选择功能(0-3): "); fflush(stdin); scanf("%c",&choice); } switch(choice) { case '1': if(pNew == NULL) { printf("\t对不起,无学生信息!\n"); } else { //冒泡排序 Stu *p = NULL; Stu *q = NULL; Stu *r = NULL; Stu n; for(p = pHead; p; p = p->next) { for(q = p->next; q; q = q->next) { if(p->id > q->id) { n = *p; *p = *q; *q = n; r = p->next; p->next = q->next; q->next = r; } } } printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t-------------------------------------------------------------\n"); while(pNew) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",pNew->id,pNew->name,pNew->sex,pNew->teacher,pNew->years,pNew->date,pNew->score); pNew = pNew->next; } } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '2': printAll_1(pHead); printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '3': printAll_2(pHead); printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '0': return; } } void printAll_1(Stu *pHead) { Stu *pNew = pHead; if(pNew == NULL) { printf("\t对不起,无学生信息!\n"); } else { Stu *p = NULL; Stu *q = NULL; Stu *r = NULL; Stu n; for(p = pHead; p; p = p->next) { for(q = p->next; q; q = q->next) { if(strcmp(p->name,q->name) > 0) { n = *p; *p = *q; *q = n; r = p->next; p->next = q->next; q->next = r; } } } printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t-------------------------------------------------------------\n"); while(pNew) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",pNew->id,pNew->name,pNew->sex,pNew->teacher,pNew->years,pNew->date,pNew->score); pNew = pNew->next; } } } void printAll_2(Stu *pHead) { Stu *pNew = pHead; if(pNew == NULL) { printf("\t对不起,无学生信息!\n"); } else { Stu *p = NULL; Stu *q = NULL; Stu *r = NULL; Stu n; for(p = pHead; p; p = p->next) { for(q = p->next; q; q = q->next) { if(p->score < q->score) { n = *p; *p = *q; *q = n; r = p->next; p->next = q->next; q->next = r; } } } printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t-------------------------------------------------------------\n"); while(pNew) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",pNew->id,pNew->name,pNew->sex,pNew->teacher,pNew->years,pNew->date,pNew->score); pNew = pNew->next; } } } void data_statistics(Stu *pHead) //3种打印方式,通过多遍遍历链表 { char choice; float score; Stu *p,*q,*a,*b; p = q = a = b = pHead; printf("\n\n"); printf("\t---------------------------------------------------------\n"); printf("\t| ***统计信息报表*** |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 1.分性别打印报表 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 2.分成绩打印报表 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 3.分性别和成绩打印报表 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t| 0.返回主菜单 |\n"); printf("\t---------------------------------------------------------\n"); printf("\t请选择显示方式: "); fflush(stdin); scanf("%c",&choice); while(choice < '0' || choice > '3') { printf("\t请重新选择功能(0-3): "); fflush(stdin); scanf("%c",&choice); } switch(choice) { case '1': printf("\t男: \n"); printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t-------------------------------------------------------------\n"); while(p) { if(strcmp(p->sex,"男") == 0) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",p->id,p->name,p->sex,p->teacher,p->years,p->date,p->score); p = p->next; } else p = p->next; } printf("\n"); printf("\t女: \n"); printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t-------------------------------------------------------------\n"); while(q) { if(strcmp(q->sex,"女") == 0) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",q->id,q->name,q->sex,q->teacher,q->years,q->date,q->score); q = q->next; } else q = q->next; } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '2': printf("\t你想要以多少分为分界线: "); scanf("%f",&score); printf("\t%.1f分以下: \n",score); printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t-------------------------------------------------------------\n"); while(p) { if(p->score < score) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",p->id,p->name,p->sex,p->teacher,p->years,p->date,p->score); p = p->next; } else p = p->next; } printf("\n"); printf("\t%.1f分及以上: \n",score); printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t-------------------------------------------------------------\n"); while(q) { if(q->score >= score) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",q->id,q->name,q->sex,q->teacher,q->years,q->date,q->score); q = q->next; } else q = q->next; } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '3': printf("\t你想要以多少分为分界线: "); scanf("%f",&score); printf("\t%.1f分及以上男生: \n",score); printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t-------------------------------------------------------------\n"); while(a) { if(strcmp(a->sex,"男") == 0 && a->score >= score) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",a->id,a->name,a->sex,a->teacher,a->years,a->date,a->score); a = a->next; } else a = a->next; } printf("\n"); printf("\t%.1f分及以上女生: \n",score); printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t-------------------------------------------------------------\n"); while(b) { if(strcmp(b->sex,"女") == 0 && b->score >= score) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",b->id,b->name,b->sex,b->teacher,b->years,b->date,b->score); b = b->next; } else b = b->next; } printf("\n"); printf("\t%.1f分以下男生: \n",score); printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t-------------------------------------------------------------\n"); while(p) { if(strcmp(p->sex,"男") == 0 && p->score < score) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",p->id,p->name,p->sex,p->teacher,p->years,p->date,p->score); p = p->next; } else p = p->next; } printf("\n"); printf("\t%.1f分以下女生: \n",score); printf("\t学号\t姓名\t性别\t老师\t年龄\t入学时间\t入学成绩\n"); printf("\t-------------------------------------------------------------\n"); while(q) { if(strcmp(q->sex,"女") == 0 && q->score < score) { printf("\t%ld\t%s\t%s\t%s\t%d\t%s\t%.1f\n",q->id,q->name,q->sex,q->teacher,q->years,q->date,q->score); q = q->next; } else q = q->next; } printf("\n"); printf("\t请按任意键继续..."); getchar(); return; case '0': return; } } void DeleteLink(Stu *pHead) //销毁链表 { Stu *q = pHead; if(pHead == NULL) return; while(pHead) { q = pHead->next; free(pHead); pHead = q; } pHead = NULL; } Stu *read_file(Stu *pHead) //读盘,直接连接到链表 { FILE *fp; Stu *pEnd,*pNew; fp = fopen("d:\\code\\student.txt","r"); //文件名自己设置 if(fp == NULL) { printf("\t打开失败,按任意键退出!"); getchar(); } pNew = (Stu *)malloc(LEN); //分配内存 while(fscanf(fp,"%ld %s %s %s %d %s %f",&pNew->id,pNew->name,pNew->sex,pNew->teacher,&pNew->years,pNew->date,&pNew->score) != EOF) { count++; //记录 pNew->next = NULL; if(pHead == NULL) pHead = pNew; else { pEnd = pHead; while(pEnd && pEnd->next != NULL) pEnd = pEnd->next; pEnd->next = pNew; } pNew = (Stu *)malloc(LEN); //再次分配内存 } free(pNew); //最后一次分配内存是没有用到的,要释放掉 fclose(fp); getchar(); return pHead; } void save_file(Stu *pHead) //存盘 { FILE *fp; Stu *p = pHead; fp = fopen("d:\\code\\student.txt","w"); //文件名自己设置 if(fp == NULL) { printf("\t打开失败,按任意键退出!"); getchar(); } if(p == NULL) getch(); else { while(p) { fprintf(fp,"%ld %s %s %s %d %s %.1f",p->id,p->name,p->sex,p->teacher,p->years,p->date,p->score); fprintf(fp,"\n"); p = p->next; } printf("\n\n"); printf("\t存盘成功!"); } fclose(fp); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。