資源簡介
C語言課程設計,學生學籍管理系統,存入、修改、插入函數帶有查重函數,可自動檢查文件是否為空,帶有密碼登陸和修改密碼功能

代碼片段和文件信息
/*???學生信息管理系統
???????學生學籍管理系統
1、輸入學生信息?當輸入數據為0時停止輸入
2、存入、修改、插入函數帶有查重函數
3、可自動檢查文件是否為空
4、帶有密碼登陸和修改密碼功能
5、第一次打開時且文件內容為空時需存入數據再操作,否則可能會出錯。
*/
#include
#include
#include
#include
struct?date
{
????char?sno[15];
????char?name[14];
????char?sex[5];
????int?age;
????char?native[20];
????char?dept[20];
????char?major[20];
????char?clas[10];
};
typedef?struct?student
{
????struct?date?d;
????struct?student?*?next;
}N;
void?menu1();//?單函數
void?menu2();//管理員菜單
void?menu3();?//普通用戶菜單函數
void?file_save();//保存文件
void?file_read();//讀取文件
void?creat_list();//創建鏈表
void?insert_date();//添加數據
void?delete_date();//刪除數據
void?treavese_list();//輸出鏈表
void?sort();//按學號排序
void?modification(N?*?p1);//修改信息
void?input(struct?date?*?q);//輸入數據
void?output(struct?date?*?q);//輸出數據
int?find(char?n[]);//查找學生
int?find2(char?n[]);//查重
int?enter();//登陸函數
N?*?Head?*?Pnew;//定義一個頭指針與循環指針
int?main()
{
????system(“color??fc“);
????file_read();
????menu1();
????return?0;
}
void?file_read()
{
????FILE?*?fp;
????if(NULL?==?(fp?=?fopen(“s_status.txt““rb“)))
????{
????????fopen(“s_status.txt““wb“);
????}
????int?a;
????a?=?ftell(fp);
????fseek(fp02);
????if(a?!=?ftell(fp))
????{
????????//insert_date();
????????printf(“文件不為空\n“);
????????rewind(fp);
????}
????else
????{
????????printf(“文件為空!請存入\n“);
????????rewind(fp);
????}
????Head?=?(N?*)malloc(sizeof(N));
????if(NULL?==?Head)
????{
????????printf(“內存分配失敗!!!“);
????????exit(-1);
????}
????Pnew?=?(N?*)malloc(sizeof(N));
????Head->next?=?Pnew;
????struct?date?*?q;//定義一個內層結構體指針,用來存放文件中的數據
????q?=?&Pnew->d;
????N?*?p1;//循環指針
????p1?=?Pnew;
????while(fread(qsizeof(struct?date)1fp))
????{
????????p1?=?Pnew;
????????Pnew?=?(N?*)malloc(sizeof(N));
????????p1->next?=?Pnew;
????????q?=?&Pnew->d;
????}
????p1->next?=?NULL;
????free(Pnew);//最后一個空間沒有存放數據?,釋放掉。
}
void?creat_list()
{
????N?*?tail;
Head?=?tail?=?(N?*)malloc(sizeof(N));
????if(NULL?==?Head)
{
printf(“內存分配失敗!!!“);
exit(-1);
}
int?i?=?0;//在第一次循環時不需要查重
while(1)
{
????i++;
N?*?Pnew?=?(N?*)malloc(sizeof(N));
printf(“\n“);
input(&Pnew->d);
if(i?!=?1?&&?1?==?(find2(Pnew->d.sno)))
????????{
????????????printf(“此學號已存在!\n“);
????????????continue;
????????}
if(Pnew->d.age?==?0)
????????{
????????????free(Pnew);
????????????break;
????????}
tail->next?=?Pnew;
????????Pnew->next?=?NULL;
????????tail?=?Pnew;
}
}
void?insert_date()
{
????char?n[20];
N?*?p1;//?循環指針
printf(“添加在哪個學號的后面:“);
scanf(“%s“n);
p1?=?Head->next;
if(NULL?==?p1)
????{
????????printf(“文件為空,請存入\n“);
????????return;
????}
while(p1?!=?NULL)
{
if(strcmp(np1->d.sno)?==?0)
{
Pnew?=?(N?*)malloc(sizeof(N));
printf(“添加學生信息為:\n“);
input(&Pnew->d);
if(find2(Pnew->d.sno)?==?1)
????????????{
????????????????printf(“此學號已存在!\n“);
????????????????printf(“\n1、繼續添加“);
????????????????printf(“\n2、返回菜
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????112??2016-11-21?16:55??s_status.txt
?????文件???????????0??2016-11-08?21:54??密碼
?????文件???????12352??2016-01-01?20:43??學生學籍管理系統.c
?????文件??????141068??2016-11-21?16:56??學生學籍管理系統.exe
- 上一篇:c/c++解決迷宮問題
- 下一篇:408計算機綜合教材書籍
評論
共有 條評論