資源簡介
已經壓縮,能直接使用,功能也比較齊全,但是有一些BUG.
代碼片段和文件信息
/*
*?C語言學生信息管理系統(動態鏈表版)
*?作者:zhangyonghang
*?時間:2015年
*?功能:增添新鍵數據、修改刪除數據、查詢統計數據
*?平臺:linux
*/
#include?“ssss.h“
int??menu_guanliyuan()
{
int?a=0;
printf(“*---------------------------*\n“);
printf(“*???????????????????????????*\n“);
printf(“*?????\033[34;7m學-生-管-理-系-統\033[0m?????*\n“);
printf(“*???????????????????????????*\n“);
printf(“*???????\033[31;1m1.管理員登錄\033[0m????????*\n“);
printf(“*???????2.教師登錄??????????*\n“);
printf(“*???????3.學生登錄??????????*\n“);
printf(“*???????4.退出系統??????????*\n“);
printf(“*???????????????????????????*\n“);
printf(“*---------------------------*\n“);
printf(“請輸入功能前的序號登錄\n“);
while(1){
scanf(“%d“&a);
switch?(a)
{
case?1:
menu_print1();
menu();
break;
case?2:
?menu_print2();
menu();
break;
case?3:
menu_print3();
menu2();
break;
case?4:
break;
default:
printf(“數字錯誤請重新輸入\n“);
?break;
?
}
if(a==4)
return?0;
setbuf(stdinNULL);
}
}
struct?Student?{
char?num[10];??/*學號*/
char?name[20];?/*姓名*/
char?sex[10];??/*性別*/
int?age;???????/*年齡*/
char?phone[12];/*電話*/
char?qq[12];???/*QQ號*/
float?cscore;??/*C語言成績*/
float?escore;??/*英語成績*/
struct?Student?*next;
};
char?filename[30];//全局變量,用來保存要打開的文件名字
/*生成鏈表*/
struct?Student?*Creat(int?n)?{
void?menu_print_in(void);
struct?Student?*head;
struct?Student?*p1?*p2;
system(“clear“);int?i=0;
for(i=1;i p1?=?(struct?Student*)malloc(LEN);
menu_print_in();
scanf(“%s%s%s%d%s%s%f%f“p1->nump1->namep1->sex
&p1->agep1->phonep1->qq&p1->cscore&p1->escore);
p1->next?=?NULL;
if(i==1)?{
head?=?p2?=?p1;
}
else?{
p2->next?=?p1;
p2?=?p1;
}
}
return(head);
}
/*數據存盤(wb只寫)*/
void?WriteData_wb(struct?Student?*head)?{
FILE?*fp;
struct?Student?*p;
if((fp?=?fopen(filename?“wb“))==NULL)
printf(“\a?error!?Can?not?open?the?file!“);
p?=?head;
while(p!=NULL)?{
if(fwrite(pLEN1fp)!=1)?{
printf(“寫入數據出錯\n“);
fclose(fp);
return;
}
p=p->next;
}
fclose(fp);
}
/*數據存盤(ab追加)*/
void?WriteData_ab(struct?Student?*head)?{
FILE?*fp;
struct?Student?*p;
if((fp?=?fopen(filename?“ab“))==NULL)
printf(“\a?error!?Can?not?open?the?file!“);
p?=?head;
while(p!=NULL)?{
if(fwrite(pLEN1fp)!=1)?{
printf(“寫入數據出錯\n“);
fclose(fp);
return;
}
p=p->next;
}
fclose(fp);
}
/*讀取數據*/
/*讀取數據文件保存到鏈表中?,返回指向此鏈表頭指針*/
struct?Student?*ReadData(void)?{
struct?Student?*head?=?NULL;
struct?Student?*p1?*p2;//s?=?p1;p?=?p2;
FILE?*fp;
if((fp=fopen(filename“rb+“))==NULL)
{
printf(“打開文件出錯\n“);
exit(0);
}
while(!feof(fp))?{
if((p1=(struct?Student*)malloc(LEN))==NULL){
printf(“內存申請出錯\n“);
fclose(fp);
exit(0);
}
if(fread(p1LEN1fp)!=1){
free(p1);
break;
}
if(head==NULL)
head=p2=p1;
else{
p2->next=p1;
p2=p1;
}
}
fclose(fp);
return?(head);
}
/*【1】全量查詢*/
void?Print_inquire_all(void)?{
void?menu_print_out(void);
struct?Student?*pt;
pt?=?ReadData();
menu_print_out();
do?{
printf(“%-10s%6s%8s%4d%13s%11s??%4.1f?%4.1f?%4.1f?%4.1f\n“
pt->numpt->namept->sexpt->agept->phonept->qqpt->cscore
pt-
- 上一篇:預測分析表
- 下一篇:華中科技大學C語言復習資料
評論
共有 條評論