学生奖学金管理系统之C语言 您所在的位置:网站首页 学生管理系统架构图 学生奖学金管理系统之C语言

学生奖学金管理系统之C语言

2023-04-19 08:38| 来源: 网络整理| 查看: 265

设计任务目的与要求

进一步掌握和利用 C 语言进行程设计的能力;

进一步理解和运用结构化程设计的思想和方法;

初步掌握开发一个小型实用系统的基本方法;

学会调试一个较长程序的基本方法;

学会利用流程图或 N-S 图表示算法;

掌握书写程设计开发文档的能力(书写课程设计报告);

设计内容总体设计

说明包含几大功能模块

画出系统功能模块结构图和系统流程图

数据结构设计及用法说明

详细设计

函数名字:

函数功能:

数据结构设计描述,参数说明

实现过程:写算法或解决思路,贴(NS 图或流程图)

学生奖学金管理系统流程图如下

使用到的结构体变量:

struct Student { char Sid[10]; char Sclass[20]; char Sname[20]; int Math; int English; int Physic; int Sum; int rank; struct Student *next; };

简介:以上的结构体为学生奖学金管理系统的核心部分,是贯穿整个系统的灵魂。存储和读取都是以结构体的形式进行的,每个结构体包含着丰富的信息。

第一板块:学生成绩的录入

使用到的函数有:

int main(); (控制主流程) void ShowMenu(); (显示主菜单) struct Student * in_stuNode(); (从键盘中输入的数据创建链表) void Record(struct Student *head); (从链表中的数据写入文件)

函数简介:先把用户输入的数据用链表储存起来,然后链表遍历,并写入文件中。

程序流程图分别如下

函数 3( 创建 stu 链表):用户输入表中相关信息(格式如流程图所示),输入学号为@输入结束。

函数 4( stu 链表写入文件):成功写入文件, 在屏幕中输出 Record ok!)

第二板块:显示全部学生成绩信息

使用到的函数有:

int main();(控制主流程) void Show_stuNode();(从链表中输出到屏幕) struct Student * File_stuNode();(从文件中读取数据,建立链表)

函数简介:由于要经常对文件中数据操作,为了方便,把文件的数据存储到链表中,对链表的操作就是对文件中数据操作。

函数 2 简介:

程序流程图分别如下

函数 3 简介:

第三板块:条件查询学生信息

使用到的函数有:

int main();(控制主流程) void Search();(Search 主菜单,控制流程) void SearchByRank();(按名次查询某学生的个人成绩) void SearchByClass();(按班级查询班级前 3 名学生的个人成绩) void SearchByScore();(按成绩段查询某学生的个人成绩) void SearchBySid() NEW :ADD FILE void SearchByName() NEW :ADD FILE struct Student * File_stuNode();(从文件中读取数据,建立链表)

程序流程图分别如下

函数 3 简介:

函数 4 简介:

函数 5 简介:

第四板块:条件统计学生信息

使用到的函数有:

int main();(控制主流程) void Statistics();(统计主菜单,控制流程) void StatByStu();(按学生统计所有人的总分) void StatByClass();(按班统计每个班的总分) void StatByProject(); NEW :ADD FILE struct Student * File_stuNode();(从文件中读取数据,建立链表)

函数 3 简介:

函数 4 简介:

第五板块:删除学生信息

使用到的函数有:

int main();(控制主流程) struct Student * File_stuNode();(从文件中读取数据,建立链表) void Delete();(删除学生信息) void Record(struct Student *head);(从链表中的数据写入文件)

函数 3 简介:

第六板块:添加学生信息

使用到的函数有:

int main();(控制主流程) void Add();(调用其他函数,完成添加功能) struct Student * in_stuNode(); (从键盘中输入的数据创建链表) struct Student * File_stuNode(); (从文件中读取数据,建立链表) void Record(struct Student *head); (从链表中的数据写入文件)

函数简介:

第七板块:按条件排序

使用到的函数有:

int main();(控制主流程)

struct Student * File_stuNode(); (从文件中读取数据,建立链表) void ShowSort(); ( 控制sort 流程) void ShowSortBy()(调用 sort 函数,显示结果) struct Student * SortByRank(struct Student *head)(按名次排序) struct Student * SortBySid(struct Student *head)(按学号排序) void Record(struct Student *head);(从链表中的数据写入文件)

函数 5 简介:

第八板块:保存文件

使用到的函数有:

int main();(控制主流程) void SaveFile();(调用函数,保存文件) struct Student * File_stuNode();(从文件中读取数据,建立链表)

函数简介:

第九板块:复制文件

使用到的函数有:

int main();(控制主流程)

void CopyFile();(将文件 1 复制到文件 2)

函数简介:

实验结果与数据分析

图中应反映各种情况,说明图中表达的数据含义

图中应看到输入数据和输出结果

第一板块:

一运行会出现主菜单

输入错误会提示

用户输入学生信息界面

第二板块:

第三板块:

(必须先进行排名)

输入名次后 会把所有同名次的学生信息输出

输入班级后 会把班级前三名的学生信息输出

有 Math ,English, Physics 三科成绩

输入分数段 ,如果输入 90-80 会提示错误

没有找到 符合条件 会输出 no found the student

第四板块:

执行完操作一后, 在 C 盘目录下 student.txt 可以看到每个学生成绩总分

执行完操作一后, 在 C 盘目录下 student1.txt 可以看到班级总分那一列 有总分了

第五板块:

输入 学号

可以在 option 2 下看到 学号为 201501001 的学生信息没有了

第六板块:

操作跟学生成绩录入一样, 可以添加多个学生

可以在 option 2 下看到 学号为 201501001 的学生信又再增加回来了

第七板块:

执行完成操作 1 可以看到

学生信息 按 名次由高到低 排序

执行完成操作 2 可以看到

学生信息 按 学号 由 低 到高 排序

第八板块:

输入 你想保存的的文件的文件名

在 C:下可以看到 以保存

第九板块:

输入 你想保存的文件名

输入你的文件 副本名

在 C:下可以看到 以保存

问题分析

用 fwrite()输入文件,用 Txt 打开乱码?

因为 fwrite() 是用二进制写入文件的,而 txt 记事本是以 Ascll 码翻译的,故显示是乱码。

在 TC 下 fopen()打开文件失败,一直返回空指针?

因为 TC 是在虚拟 C:下 ,存到 D:盘下会找不到

free()

体会,总结

课程设计完成了哪些功能,有没有什么扩展功能 还有哪些地方需要改进,及通过两周的课程设计有何收获,调试程序的体会等

这次课程设计让我学到了很多东西,感受也颇多,首先就是刚拿到题目的时候,心想了一下觉得不是很难,然后我还遇到一些当时让我匪夷所思的问题,这个问题时我从来没有遇到过的,那就是关于 free 的问题。因为之前没有 free 掉节点的习惯,但后来发现这个是有必要的,所以我就开始尝试 free 没用的内存,于是问题就来了。刚开始我愚蠢的认为 free 就是直接把定义的指针 free 掉就好了……例如定义了*p1,*p2,我就直接 free 掉 p1,p2.就以为链表所有占用的临时内存就释放掉了。Free 不正确这会导致灾难性的后果,我的系统经常用着用着就卡死不动,起初我认为是死循环,但是我分布运行也会突然卡死,有时分布运行又可以通过这个函数,但跳出这个函数就又卡死了!我当时真的是觉得无比的奇怪,冷汗都吓出来了。我初步认为是电脑的问题,于是我换舍友的电脑试,居然有时卡死有时又正常……更让我想不通。后来认为是 Tc 的问题,想找个有 Vc 的人去他电脑里试试这个程序会不会卡死。那天去上课会回来,我仔细分析了一下,以前不会出现的问题而现在出现了,应该不是 Tc 的问题,毕竟它也是经过 20 年考验的,所以我就想了一下自己的代码与之前有什么不同,我发现就是比平常 free 频繁很多,所以我把 free 注释掉,结果运行就正常了,我很奇怪,于是上网查结果还真是这个问题!过几天刚好老师讲到了这个 free 的问题,心里感触很多呀。

还有就是关于格式的问题,系统的一条一条的横杠以及那些表格都是经过很多次的修改和校正的,虽然外观还是很难看,但是的却很难让它们对齐,伤透脑筋了。总之这次课程设计给了我很多启示吧,感触挺多的,自己也很努力很认真的完成了,虽然做出来的效果很一般,但是也算给自己的大一的 C 学习划伤一个圆满的句号吧。

参考文献

C 程序设计(谭浩强 编著)

程序设计(第四版)学习辅导 (谭浩强 编著)

C 程序设计语言(第二版 新版) (Brian Kernighan && Denis M.Ritchie 著)

C 语言入门经典(第四版) (Ivor Horton 著)

附录:程序清单

(算法、变量和函数都要有注释)

源代码说明:由于 Word 文档单行较短,很多代码因为过长而显得格式不美观,这些代码在记事本上也有可能不严格对齐,而在 Tc 上是对齐的。鉴于这种问题,望谅解。

Source.h struct Student { char Sid[10]; char Sclass[20]; char Sname[20]; int Math; int English; int Physic; int Sum; int rank; struct Student *next; }; void ShowMenu(); struct Student * in_stuNode(); //从键盘中输入的数据创建链表 void Record(struct Student *head) //从链表中的数据 写入文件 struct Student * File_stuNode() //从文件中读取的数据创建链表 void Show_stuNode(); void ShowMenu3() // 查询菜单 void SortRank(); void SearchByRank(); void SearchByClass(); void SearchByScore(); void Search(); void ShowMenu4(); void StatByStu(); void StatByClass(); void Statistics(); struct Student * RankSort(struct Student * head); struct Student * SortByRank(struct Student *head); struct Student * SortBySid(struct Student *head); void ShowSortBy(int i); void ShowSort(); void Delete(); void Add(); void CopyFile(); void SaveFile() ; int main(); 001.c # include # include # include # include “Source.h” # define SIZE sizeof(struct Student) //从链表中的数据 写入文件 void Record(struct Student *head) { FILE *fp; struct Student *p1; if((fp = fopen("D:\\Course\\student.txt", "w")) == NULL) { printf("cannot open this file\n"); return; } //// 调用 in_stuNode() = head; while(p1 != NULL) { fprintf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank); /* if(fwrite(p1, SIZE, 1, fp) != 1) { printf("file write error\n"); }*/ = p1->next; } if(p1 == NULL) { printf("Record ok!\n"); } free(p1); free(head); fclose(fp); } void ShowMenu() { printf("\n***********************************************************\n"); printf("\twelcome to Stugent bonus management system\n\n"); printf("\t1-------------- Record\n"); printf("\t2-------------- Show all record\n"); printf("\t3-------------- Find\n"); printf("\t4-------------- Statistics\n"); printf("\t5-------------- Delete\n"); printf("\t6-------------- Add\n"); printf("\t7-------------- Sort\n"); printf("\t8-------------- Save File\n"); printf("\t9-------------- Copy File\n"); printf("\t10------------- Exit\n\n"); printf("***********************************************************\n"); } int main() { int option; do { ShowMenu(); printf("\t请选择要执行的操作: "); scanf("%d", &option); getch(); switch(option) { case 1: Record(in_stuNode()); break; case 2: Show_stuNode(); break; case 3: Search(); break; case 4: Statistics(); break; case 5: Delete(); break; case 6: Add(); break; case 7: ShowSort(); break; case 8: SaveFile(); break; case 9: CopyFile(); break; case 10: break; default : printf("input error!"); } } while(option != 10); return 0; } 002.c # include # include # include # include “Source.h”

/从文件中读取的数据创建链表

struct Student * File_stuNode() { FILE *fp; int n = 0; struct Student *head, *p2, *p1; if((fp = fopen("C:\\student.txt", "rb")) == NULL) { printf("cannot open this file\n"); return NULL; } head = NULL; = p1 = (struct Student *)malloc(SIZE); fscanf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d", p1->Sid, p1->Sclass, p1->Sname, &p1->Math, &p1->English, &p1->Physic, &p1->Sum, &p1->rank); // fread(p1, SIZE, 1, fp); while(!feof(fp)) { n++; if(n == 1) { head = p2; } else { ->next = p1; } = p1; = (struct Student *)malloc(SIZE); fscanf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d", p1->Sid, p1->Sclass, p1->Sname, &p1->Math, &p1->English, &p1->Physic, &p1->Sum, &p1->rank); // fread(p1, SIZE, 1, fp); } ->next = NULL; fclose(fp); return head; } void Show_stuNode() { struct Student *p, *head; printf("---------------------------STUDENT------------------------------------\n"); printf("|no |class |name |sc1 |sc2 |sc3 |sum |order|\n"); printf("----------------------------------------------------------------------\n"); head = File_stuNode(); ////调用 File_stuNode() = head; while(p != NULL) { printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p->Sid, p->Sclass, p->Sname, p->Math, p->English, p->Physic, p->Sum, p->rank); = p->next; } } 003.c # include # include # include # include “Source.h” void SortRank() { int i; struct Student *p1, *head, *p2; head = File_stuNode(); = head; while(p1 != NULL) { = 1; = head; while(p2 != NULL) { if(p1->Sum < p2->Sum) { i++; } = p2->next; } ->rank = i; = p1->next; } Record(head); } void SearchByRank() { struct Student *p1, *head; int number; head = File_stuNode(); = head; if(p1->rank == 0) { printf("you don’t have sort the student,please return the mainmemu operate the option 7\n "); } SortRank(); //排名; printf("请输入要查询的名次:"); scanf("%d", &number); while(p1 != NULL) { if(p1->rank == number) { printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank); } = p1->next; } free(p1); free(head); } void SearchByClass() { int i = 1; char Class[10] = {0}; struct Student *p1, *head, *p2; printf("请输入要查询的班级:如201501 "); scanf("%s", Class); head = File_stuNode(); = head; while(p1 != NULL) { if(strcmp(Class, p1->Sclass) == 0) { = 1; = head; while(p2 != NULL) { if(strcmp(Class, p2->Sclass) == 0) { if(p1->Sum < p2->Sum) { i++; } } = p2->next; } if(i Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank); } else if(i > 3) { break; } } = p1->next; } free(p1); free(head); } void SearchByScore() { int i = 0; struct Student *p1, *head; int scope1, scope2; char course[10] = {0}; printf("请输入要查询的分数段:如 70 - 80 \n"); scanf("%d-%d", &scope1, &scope2); if(scope1 >= scope2) { printf("scope2 must be bigger than scope1!\n"); return; } printf("请输入要查询的科目:(Math、English、Physic) \n"); scanf("%s", course); if(!(strcmp(course, "Math") == 0 || strcmp(course, "English") == 0 || strcmp(course, "Physic") == 0)) { printf("no found the course\n"); return; } head = File_stuNode(); = head; while(p1 != NULL) { if(strcmp(course, "Math")==0) { if(p1->Math >= scope1 && p1->Math Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank); i++; } } else if(strcmp(course, "English")==0) { if(p1->English >= scope1 && p1->English Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank); i++; } } else if(strcmp(course, "Physic")==0) { if(p1->Physic >= scope1 && p1->Physic Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank); i++; } } = p1->next; } if(i == 0) { printf("no the student adopt to adition\n"); } } void ShowMenu3() { printf("\t****************************************\n"); printf("\t1----------search the student by the rank\n"); printf("\t2----------search the top three student by the class\n"); printf("\t3----------search the student by the scope of score\n"); printf("\t4----------search the student by Name\n"); printf("\t5----------search the student by ID\n"); printf("\t6----------exit\n"); printf("\t****************************************\n"); } void SearchByName() { char name[15]; int tag = 0; struct Student *p1, *head; printf("please input the Name\n"); scanf("%s", name); head = File_stuNode(); = head; while(p1 != NULL) { if(strcmp(p1->Sname,name) == 0) { printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank); tag = 1; } = p1->next; } if(tag == 0) { printf("NO found the student\n"); } } void SearchBySid() { char id[15]; int tag = 0; struct Student *p1, *head; printf("please input the student ID\n"); scanf("%s", id); head = File_stuNode(); = head; while(p1 != NULL) { if(strcmp(p1->Sid,id) == 0) { printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank); tag = 1; } = p1->next; } if(tag == 0) { printf("NO found the student\n"); } } void Search() { int op; do { ShowMenu3(); printf("\t请选择要执行的操作: "); scanf("%d", &op); switch(op) { case 1: SearchByRank(); break; case 2: SearchByClass(); break; case 3: SearchByScore(); break; case 4: SearchByName(); break; case 5: SearchBySid(); break; case 6: break; default : printf("input error!\n"); } } while(op != 6); } 004.c # include # include # include # include “Source.h” void StatByClass() { char Class[10][10] = {0}; int ClassSum[10] = {0}; int i = 0; // 记录class总数 int j; int tag = 1; struct Student *head, *p1; FILE *fp; head = File_stuNode(); = head; while(p1 != NULL) { tag = 1; for(j = 0; j < i; j++) { if(strcmp(Class[j], p1->Sclass) == 0) { tag = 0; break; } } if(tag == 1) { strcpy(Class[i++], p1->Sclass); } = p1->next; } = head; while(p1 != NULL) { for(j = 0; j < i; j++) { if(strcmp(p1->Sclass, Class[j]) == 0) { ClassSum[j] += p1->Sum; } } = p1->next; } if((fp = fopen("C:\\student.txt", "w+")) == NULL) { printf("cannot open this file\n"); return; } for(j = 0; j < i; j++) { printf("%s %d\n", Class[j], ClassSum[j]); } } void StatByStu() { struct Student *head, *p1; head = File_stuNode(); = head; while(p1 != NULL) { ->Sum = p1->Math + p1->English + p1->Physic; = p1->next; } Record(head); } void ShowMenu4() { printf("\t****************************************\n"); printf("\t1-------------- 总计\n"); printf("\t2-------------- 分班统计\n"); printf("\t3----------exit\n"); printf("\t****************************************\n"); } void StatByProject() { struct Student *head, *p1; int i; Char project[3] = {0}; head = File_stuNode(); = head; while(p1 != NULL) { project[0] += p1->Math; project[1] += p1->English; project[3] += p1->Physic; = p1->next; } for(i = 0; i < 3; i++) { printf("%d\n", project[i]); } } void Statistics() { int op; do { ShowMenu4(); printf("\t请选择要执行的操作: "); scanf("%d", &op); switch(op) { case 1: StatByStu(); break; case 2: StatByClass(); break; case 3: StatByProject(); break; case 4: break; default : printf("input error!\n"); } } while(op != 4); } 005.c # include # include # include # include “Source.h” void Delete() { struct Student *p1, *head, *p2; char stuid[10] = {0}; int tag = 0; head = File_stuNode(); printf("请输入要删除的学生学号:\n"); scanf("%s", stuid); = head; = NULL; while(p1 != NULL) { if(strcmp(p1->Sid, stuid) == 0) { if(p2 == NULL) { head = p1->next; // 删除是 head 结点 tag = 1; break; } else { if(p1->next == NULL) { ->next = NULL; // 删除是 尾节点 tag = 1; break; } ->next = p1->next; tag = 1; break; } } = p1; = p1->next; } if(tag == 0) { printf("no found the student!\n"); } else { Record(head); } } 006.c # include # include # include # include “Source.h” void Add() { struct Student * head1, *head2, *p1, *head; head1 = File_stuNode(); head2 = in_stuNode(); = head1; if(p1 != NULL) { while(p1->next != NULL) { = p1->next; } ->next = head2; head = head1; } else { head = head2; } Record(head); } 007.c # include # include # include # include “Source.h” /*

对链表 按 rank 实现从小到大排序, 并返回链表的头指针。

*/ struct Student * SortByRank(struct Student *head) { struct Student *p1, *p2, *p3; struct Student t; for(p1 = head; p1 != NULL; p1 = p1->next) { = p1; for(p2 = p1->next; p2 != NULL; p2 = p2->next) { if(p3->rank > p2->rank) { = p2; } } if(p3 != p1) { English = p1->English; Math = p1->Math; Physic = p1->Physic; strcpy(t.Sclass, p1->Sclass); strcpy(t.Sid, p1->Sid); strcpy(t.Sname, p1->Sname); ->English = p3->English; ->Math = p3->Math; ->Physic = p3->Physic; strcpy(p1->Sclass, p3->Sclass); strcpy(p1->Sid, p3->Sid); strcpy(p1->Sname, p3->Sname); ->English = t.English; ->Math = t.Math; ->Physic = t.Physic; strcpy(p3->Sclass, t.Sclass); strcpy(p3->Sid, t.Sid); strcpy(p3->Sname, t.Sname); } } // 统计总分; = head; while(p1 != NULL) { ->Sum = p1->Math + p1->English + p1->Physic; = p1->next; } head = RankSort(head); // 排名; return head; } /*

对链表 按 Sid 实现从小到大排序, 并返回链表的头指针。

*/ struct Student * SortBySid(struct Student *head) { struct Student *p1, *p2, *p3; struct Student t; for(p1 = head; p1 != NULL; p1 = p1->next) { = p1; for(p2 = p1->next; p2 != NULL; p2 = p2->next) { if(strcmp(p3->Sid, p2->Sid) > 0) { = p2; } } if(p3 != p1) { English = p1->English; Math = p1->Math; Physic = p1->Physic; strcpy(t.Sclass, p1->Sclass); strcpy(t.Sid, p1->Sid); strcpy(t.Sname, p1->Sname); ->English = p3->English; ->Math = p3->Math; ->Physic = p3->Physic; strcpy(p1->Sclass, p3->Sclass); strcpy(p1->Sid, p3->Sid); strcpy(p1->Sname, p3->Sname); ->English = t.English; ->Math = t.Math; ->Physic = t.Physic; strcpy(p3->Sclass, t.Sclass); strcpy(p3->Sid, t.Sid); strcpy(p3->Sname, t.Sname); } } // 统计总分; = head; while(p1 != NULL) { ->Sum = p1->Math + p1->English + p1->Physic; = p1->next; } head = RankSort(head); // 排名; return head; } void ShowSortBy(int i) { struct Student *head, *p1; head = File_stuNode(); = head; if(i == 1) { = SortByRank(p1); } else if(i == 2) { = SortBySid(p1); } while(p1 != NULL) { printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank); = p1->next; } } void ShowSort() { int op; do { printf("\t****************************************\n"); printf("\t1----------对所有学生按名次排序\n"); printf("\t2----------对所有学生按学号排序\n"); printf("\t3----------Exit!\n"); printf("\t****************************************\n"); printf("\t请选择要执行的操作: "); scanf("%d", &op); switch(op) { case 1: ShowSortBy(op); break; case 2: ShowSortBy(op); break; case 3: break; default : printf("input error!\n"); } } while(op != 3); } 008.c # include # include # include # include “Source.h” void SaveFile() { FILE *fp; char filename[30] = {0}; struct Student *head, *p1; scanf("%s", filename); getchar(); if((fp = fopen(filename, "w")) == NULL) { printf("open file error"); return; } head = File_stuNode(); = head; while(p1 != NULL) { fprintf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank); = p1->next; } free(head); free(p1); fclose(fp); } 009.c # include # include # include # include “Source.h” void CopyFile() { FILE *fp, *fp1; char filename[30] = {0}; char filename1[30] = {0}; struct Student *p1, stu; printf("please input the fileName\n"); scanf("%s", filename); getch(); printf("please input the fileName path\n"); scanf("%s", filename1); getch(); if((fp = fopen(filename, "r")) == NULL) { printf("open file error"); return; } if((fp1 = fopen(filename1, "w")) == NULL) { printf("open file error"); return; } = &stu; while(!feof(fp)) { fscanf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d", p1->Sid, p1->Sclass, p1->Sname, &p1->Math, &p1->English, &p1->Physic, &p1->Sum, &p1->rank); fprintf(fp1, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank); } fclose(fp); fclose(fp1); }



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有