這個(gè)是什么問(wèn)題亞
部分代碼:(主要是這里有問(wèn)題)
#define USERINFO_FILE?????????????????? "/home/ocelot/pmm/data/info.txt"
//用戶(hù)信息表記錄文檔路徑
#define SAVES_HOME_PATH???????????????? "/home/ocelot/pmm/data/"
#define _STRUCT_USER_INFO_SIZE????????? (sizeof(struct user_info))
//struct user_info類(lèi)型結(jié)構(gòu)體大小
#define _END_LOOP?????????????????????? "$!END_0"
extern struct user_info * getUserInfo()
{
??????? FILE *fp = fopen(USERINFO_FILE,"r");
??????? //若文件不存在,則返回空指針
??????? if(fp == NULL)
??????????????? return NULL;
??????? char??? buf[64];??????????????? //緩沖字符串
??????? int???? user_num = 0;?????????? //用戶(hù)數(shù)量
??????? //獲取用戶(hù)數(shù)量
??????? while(fscanf(fp,"%s",buf) != EOF)
??????? {
??????????????? if(buf[0] == '[')
??????????????????????? user_num++;
??????? }
??????? struct user_info??????? *pi = (struct user_info *)malloc(_STRUCT_USER_INFO_SIZE * (user_num+1));
??????? //動(dòng)態(tài)分配結(jié)構(gòu)體數(shù)組
??????? fclose(fp);
??????? FILE *fp_s = fopen(USERINFO_FILE,"r");
??????? //若文件不存在,則返回空指針
??????? if(fp == NULL)
??????????????? return NULL;
??????? int???? serial = 0;???????????? //讀入的用戶(hù)序號(hào)
??????? while(fscanf(fp_s,"%s",buf) != EOF)
??????? {
??????????????? //忽略注釋行
??????????????? if(buf[0] == '#')
??????????????????????? continue;
??????????????? //將Name存入數(shù)組
??????????????? if(buf[0] == '[')
??????????????????????? serial++;
if(buf[0] == 'N')
??????????????? {
??????????????????????? printf("##%s##\n",buf);
??????????????????????? //指向下一個(gè)用戶(hù)
??????????????????????? strcpy(pi->name,//getStrPointStr(buf,':')
??????????????????????????????????????? buf);
??????????????????????? pi+=(_STRUCT_USER_INFO_SIZE * 1);
??????????????? }
??????????????? //將Pw存入數(shù)組
??????????????? else if(buf[0] == 'P')
??????????????? {
??????????????????????? sprintf(pi->pw,"%s",getStrPointStr(buf,':'));
??????????????? }
??????????????? //忽略其他屬性
??????????????? else
??????????????????????? continue;
??????? }
??????? //設(shè)定結(jié)束標(biāo)志
??????? pi+=(_STRUCT_USER_INFO_SIZE * 1);
??????? sprintf(pi->name,"%s",_END_LOOP);
??????? sprintf(pi->pw,"%s",_END_LOOP);
??????? pi-=(_STRUCT_USER_INFO_SIZE * serial);
??????? //將結(jié)構(gòu)體指針指向第一個(gè)用戶(hù)
??????? fclose(fp_s);
??????? return pi;
}
輸出:
##Name:ocelot##
##Name:whisper##
##Name:xiaoyue##
##Name:xiaoyue##
##Name:xiaoyue##
##Name:xiaoyue##
##Name:xiaoyue##
登錄:
用戶(hù)列表:
[1]?? ?9??U
[2]?? ?Name:xiaoyue
[3]?? ?Name:xiaoyue
[4]?? ?Name:xiaoyue
[5]?? ?Name:xiaoyue
[6]?? ?Name:xiaoyue
[7]?? ?
改了很多次,還是有問(wèn)題
但用戶(hù)數(shù)量小于等于3個(gè)時(shí)不會(huì)有這種情況,不知道為什么
2022-05-01
看判斷那兒是不是不對(duì)
2021-07-09
編碼就不對(duì)了吧