From 4ec05fabe728256d8fd50313a8916eebeb677b95 Mon Sep 17 00:00:00 2001 From: "Hancel.Lin" Date: Thu, 12 Apr 2018 21:40:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=A1=B9=E7=9B=AE2=20C?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=E4=BB=A3=E7=A0=81bug=201.=20record.txt=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=BA=E7=A9=BA=E8=AF=BB=E5=8F=96=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E4=B9=B1=E7=A0=81=EF=BC=9B=202.=20=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E7=8E=A9=E8=AE=B0=E5=BD=95=E6=B2=A1=E6=9C=89=E5=90=8D?= =?UTF-8?q?=E5=AD=97=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 02/backend/main.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/02/backend/main.c b/02/backend/main.c index 6c7d9d4..7bd149c 100644 --- a/02/backend/main.c +++ b/02/backend/main.c @@ -31,10 +31,9 @@ int loadNickname(const char* szPath, char* szNickname, int nSize) return 0; } -int setNickname(const char* szPath) +const char* setNickname(const char* szPath, char* szNickname) { FILE *fp = 0; - char szNickname[MAX_NAME_LEN] = ""; if (!(fp = fopen(szPath, "wb"))) return 1; printf("请输入你的名字:"); @@ -42,7 +41,7 @@ int setNickname(const char* szPath) szNickname[MAX_NAME_LEN - 1] = 0; fwrite(szNickname, sizeof(szNickname), 1, fp); fclose(fp); - return 0; + return szNickname; } struct RECORD guess(char* szNickName) @@ -66,13 +65,13 @@ struct RECORD guess(char* szNickName) stRecord.nCount++; } stRecord.nCost = time(NULL) - stRecord.tBeginTime; - strcpy(stRecord.szName, szNickName); printf("你猜中了!你猜了%d次!\n", stRecord.nCount); if (0 == szNickName || 0 == strlen(szNickName)) { printf("这是你第一次玩,"); - setNickname(SETTING_PATH); + setNickname(SETTING_PATH, szNickName); } + strcpy(stRecord.szName, szNickName); return stRecord; } @@ -113,13 +112,13 @@ int view() while(!feof(fp)) { - fscanf(fp, "%d,%d,%d,%ld,%d,%s\r\n", + if(fscanf(fp, "%d,%d,%d,%ld,%d,%s\r\n", &stRecord.nRand, &stRecord.nGuess, &stRecord.nCount, <ime, &stRecord.nCost, - stRecord.szName); + stRecord.szName) < 0) continue; stRecord.tBeginTime = (time_t)ltime; localtime_s(&stTime, &stRecord.tBeginTime); @@ -162,7 +161,7 @@ int main() { case '1': save(guess(szNickname)); break; case '2': view(); break; - case '3': setNickname(SETTING_PATH); break; + case '3': setNickname(SETTING_PATH, szNickname); break; case '4': return 0; default : continue; }