为了体现我大学四年也不是白念的,当然得体现出逼格,那就从界面下手,于是我选择了ncurses这个终端字符库,最后的界面是这样的:
(1)ncurses图形库不是线程安全的,之前设计的界面如下所示:
这是之前的代码:
intreadUser(){FILE*fp;user*p=(user*)malloc(sizeof(user));user*q=(user*)malloc(sizeof(user));USER_HEAD=p;USER_MAXID=-1;fp=fopen(USER_PATH,"r+");if(fp==NULL){fp=fopen(USER_PATH,"w+");free(q);return0;}while(!feof(fp)){fscanf(fp,"%d%s%s%s%s%d\n",&(q->user_id),q->user_stid,q->user_name,q->user_address,q->user_mail,&(q->user_status));/*updateUSER_MAXID*/if(q->user_id>USER_MAXID){USER_MAXID=q->user_id;}p->next=q;p=q;q=(user*)malloc(sizeof(user));}p->next=NULL;free(q);fclose(fp);return0;}最后使用read读取,加O_CREATE也可以防止文件不存在:
char*getTimeNow(){char*timestr;time_trawtime;structtm*timeinfo;time(&rawtime);timeinfo=localtime(&rawtime);timestr=asctime(timeinfo);/*del\n*/timestr[strlen(timestr)-1]='\0';returntimestr;}