資源簡介
使用C語言,在Linux系統(tǒng)環(huán)境下,使用鏈表編寫的一個簡單的彩票管理系統(tǒng),供大家學(xué)習(xí)交流,本人經(jīng)驗有限,歡迎批評。

代碼片段和文件信息
/*
功能類fun.c文件
函數(shù)功能:
獲取當(dāng)前本地時間,創(chuàng)建四條鏈的數(shù)據(jù)文件(初始化),管理員開獎,自動兌獎
刪除失效用戶,查看所有用戶,查看所有購票,查看所有已開獎,查看彩票中心
營收記錄,用戶鏈按用戶ID排序/按用戶ID查找/按購買次數(shù)排序/按中獎次數(shù)排
序,彩票鏈按期號排序/按期號查找/按用戶ID查找/按彩票ID排序,歷史開獎鏈
按中獎金額排序/按期號排序/按期號查找,用戶購票/選擇彩票類型/選擇號碼/
查看個人信息/支付/修改個人信息/查詢購買歷史/賬戶充值,用戶密碼加密/密
碼解密
*/
#include?“fun.h“
/*****************************************
功能:獲取當(dāng)前本地時間
參數(shù):無
返回值:struct?tm?*類型的指針
******************************************/
struct?tm?*time_now()//————函數(shù)?4
{
long?t?=?0;
t?=?time(NULL);//調(diào)用時間API,獲取從1970年1月1號0點到當(dāng)前時間所歷經(jīng)的秒數(shù),日歷時間
localtime(&t);//系統(tǒng)API,將日歷時間轉(zhuǎn)換為本地時間,并且存儲在struct?tm類型的結(jié)構(gòu)體中,返回值為指向該結(jié)構(gòu)體的指針
return?(localtime(&t));
}
/*****************************************
*功能:創(chuàng)建四條鏈的文本文件,并且進(jìn)行相應(yīng)的初始化
*參數(shù):無
*返回值:int類型,1表示數(shù)據(jù)庫文件存在或者創(chuàng)建成功,
*0表示數(shù)據(jù)庫文件創(chuàng)建失敗
******************************************/
int?init_all()//————函數(shù)?49
{
USER?*user_head?=?NULL;
LOTTERY?*lottery_head?=?NULL;
HISTORY?*history_head?=?NULL;
MONEY?*money_head?=?NULL;
system(“clear“);//清屏
user_head?=?load_user(user_head);//用戶鏈加載文本文件————函數(shù)?2
lottery_head?=?load_lottery(lottery_head);//彩票鏈加載文本文件————函數(shù)?27
history_head?=?load_history(history_head);//歷史開獎鏈加載文本文件————函數(shù)?29
money_head?=?load_money(money_head);//彩票營收鏈加載文本文件————函數(shù)?31
if(user_head?==?NULL?||?lottery_head?==?NULL?||?history_head?==?NULL?||?money_head?==?NULL)
//判斷四條鏈的文本文件是否都存在
{
free_user(user_head);//包含頭節(jié)點釋放用戶鏈————函數(shù)?21
free_lottery(lottery_head);//包含頭節(jié)點釋放彩票鏈————函數(shù)?22
free_history(history_head);//包含頭節(jié)點釋放歷史開獎鏈————函數(shù)?23
free_money(money_head); //包含頭節(jié)點釋放彩票營收鏈————函數(shù)?24
printf(“\n\n\t??*??*??*??\033[;33;1m創(chuàng)?建?彩?民?數(shù)?據(jù)?庫\033[0m??*??*??*\n\n“);
user_head?=?malloc(sizeof(USER));//創(chuàng)建用戶鏈頭節(jié)點
if(user_head?==?NULL)
{
printf(“\n\n\n\033[;31;1m動態(tài)內(nèi)存分配失?。o法創(chuàng)建彩民數(shù)據(jù)庫\033[0m\n\n\n“);
return?0;//若用戶鏈頭節(jié)點創(chuàng)建失敗,則返回0,退出本函數(shù)
}
user_head->next?=?NULL;//頭節(jié)點指針域置空
printf(“\t\033[;33m請輸入彩民起始ID:\033[0m“);
scanf(“%d“&user_head->user_id);//頭節(jié)點存放用戶的起始ID(自動編號)
save_user(user_head);//用戶鏈保存文本文件頭結(jié)點也保存————函數(shù)?25
printf(“\t\033[;32m您輸入的彩民起始ID為%d\n\t彩民數(shù)據(jù)庫創(chuàng)建成功!\033[0m\n“
user_head->user_id);
printf(“\n\n\t??*??*??*??\033[;33;1m創(chuàng)?建?彩?票?數(shù)?據(jù)?庫\033[0m??*??*??*\n\n“);
lottery_head?=?malloc(sizeof(LOTTERY));//創(chuàng)建彩票鏈頭節(jié)點
if(lottery_head?==?NULL)
{
printf(“\n\n\n\033[;31;1m動態(tài)內(nèi)存分配失??!無法創(chuàng)建彩票數(shù)據(jù)庫\033[0m\n\n\n“);
return?0;//若彩票鏈頭節(jié)點創(chuàng)建失敗,則返回0,退出本函數(shù)
}
lottery_head->next?=?NULL;//頭節(jié)點指針域置空
printf(“\t\033[;33m請輸入彩票起始ID:\033[0m“);
scanf(“%d“&lottery_head->lot_id);//頭節(jié)點存放彩票的起始ID(自動編號)
save_lottery(lottery_head);//彩票鏈保存文本文件,頭結(jié)點也保存————函數(shù)?26
printf(“\t\033[;32m您輸入的彩票起始ID為%d\n\t彩票數(shù)據(jù)庫創(chuàng)建成功!\033[0m\n“
lottery_head->lot_id);
printf(“\n\n\t??*??*??*??\033[;33;1m創(chuàng)?建?開?獎?數(shù)?據(jù)?庫\033[0m??*??*??*\n\n“);
history_head?=?malloc(sizeof(HISTORY));//創(chuàng)建歷史開獎鏈頭節(jié)點
if(history_head?==?NULL)
{
printf(“\n\n\n\033[;31;1m動態(tài)內(nèi)存分配失??!無法創(chuàng)建開獎數(shù)據(jù)庫\033[0m\n\n\n“);
return?0;//若歷史開獎鏈頭節(jié)點創(chuàng)建失敗,則返回0,退出本函數(shù)
}
history_head->next?=?NULL;//頭節(jié)點指針域置空
printf(“\t\033[;33m請輸入開獎起始期號:\033[0m“);
scanf(“%d“&history_head->issue);//頭節(jié)點存放開獎的起始期號(自動編號)
save_history(history_head);//歷史開獎鏈保存文本文
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????74??2015-10-11?20:12??lottery\bin\history.txt
?????文件????????100??2015-10-11?20:12??lottery\bin\lottery.txt
?????文件??????59770??2015-09-21?19:04??lottery\bin\main
?????文件????????153??2015-10-11?20:12??lottery\bin\money.txt
?????文件????????156??2015-10-11?20:12??lottery\bin\user.txt
?????文件??????27316??2015-09-21?19:04??lottery\fun.o
?????文件???????4964??2015-09-21?19:04??lottery\history.o
?????文件???????3406??2015-09-18?15:38??lottery\include\fun.h
?????文件???????1601??2015-09-18?15:21??lottery\include\history.h
?????文件???????1826??2015-09-18?15:14??lottery\include\lottery.h
?????文件???????1837??2015-09-18?15:05??lottery\include\menu.h
?????文件???????1089??2015-09-18?14:58??lottery\include\money.h
?????文件???????1707??2015-09-18?14:57??lottery\include\user.h
?????文件???????5928??2015-09-21?19:04??lottery\lottery.o
?????文件???????1012??2015-09-21?19:04??lottery\main.o
?????文件????????640??2015-09-18?13:08??lottery\makefile
?????文件??????24416??2015-09-21?19:04??lottery\menu.o
?????文件???????3448??2015-09-21?19:04??lottery\money.o
?????文件??????63252??2015-09-21?19:03??lottery\src\fun.c
?????文件??????10365??2015-09-18?15:24??lottery\src\history.c
?????文件??????11762??2015-09-18?15:19??lottery\src\lottery.c
?????文件????????857??2015-09-18?15:12??lottery\src\main.c
?????文件??????48471??2015-09-21?15:17??lottery\src\menu.c
?????文件???????5208??2015-09-18?15:02??lottery\src\money.c
?????文件??????16594??2015-09-18?15:01??lottery\src\user.c
?????文件???????7992??2015-09-21?19:04??lottery\user.o
?????目錄??????????0??2016-05-10?14:58??lottery\bin
?????目錄??????????0??2016-05-10?14:59??lottery\include
?????目錄??????????0??2016-05-10?14:59??lottery\src
?????目錄??????????0??2016-05-10?14:59??lottery
............此處省略3個文件信息
評論
共有 條評論