From b0bbee6288ba90cc9fa3eb68d340302c266c0965 Mon Sep 17 00:00:00 2001 From: "Hancel.Lin" Date: Thu, 12 Apr 2018 09:43:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=B9=E7=9B=AE2=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=AD=E5=85=A8=E9=83=A8=E4=B8=BA=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 02/backend/main.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/02/backend/main.c b/02/backend/main.c index f37010f..6c7d9d4 100644 --- a/02/backend/main.c +++ b/02/backend/main.c @@ -37,7 +37,7 @@ int setNickname(const char* szPath) char szNickname[MAX_NAME_LEN] = ""; if (!(fp = fopen(szPath, "wb"))) return 1; - printf("Please input your Name:"); + printf("请输入你的名字:"); scanf("%s", szNickname); szNickname[MAX_NAME_LEN - 1] = 0; fwrite(szNickname, sizeof(szNickname), 1, fp); @@ -70,7 +70,7 @@ struct RECORD guess(char* szNickName) printf("你猜中了!你猜了%d次!\n", stRecord.nCount); if (0 == szNickName || 0 == strlen(szNickName)) { - printf("This is your first play."); + printf("这是你第一次玩,"); setNickname(SETTING_PATH); } return stRecord; @@ -81,7 +81,7 @@ int save(struct RECORD stRecord) FILE * fp = NULL; if(!(fp = fopen(RECORD_PATH, "ab"))) { - printf("Save Record Failed.. \n"); + printf("保存记录失败.. \n"); return 1; } fseek(fp, SEEK_END, 0); @@ -101,17 +101,18 @@ int view() { FILE * fp = NULL; struct RECORD stRecord; + long ltime = 0; + struct tm stTime = {0}; if (!(fp = fopen(RECORD_PATH, "rb"))) { - printf("You must be play first. \n"); + printf("你还没有玩过呢。 \n"); return 1; } - printf("Name\tGuess\tCount\tCost\tBegin\n"); + printf("姓名\t所猜数字\t猜测次数\t花费秒数\t开始时间\n"); while(!feof(fp)) { - long ltime = 0; fscanf(fp, "%d,%d,%d,%ld,%d,%s\r\n", &stRecord.nRand, &stRecord.nGuess, @@ -120,12 +121,15 @@ int view() &stRecord.nCost, stRecord.szName); stRecord.tBeginTime = (time_t)ltime; - printf("%s\t%d\t%d\t%d\t%s", + localtime_s(&stTime, &stRecord.tBeginTime); + + printf("%s\t%5d \t%5d \t%5d \t%d/%02d/%02d %02d:%02d:%02d", stRecord.szName, stRecord.nGuess, stRecord.nCount, stRecord.nCost, - asctime(gmtime(&stRecord.tBeginTime))); + stTime.tm_year + 1900, stTime.tm_mon, stTime.tm_mday, + stTime.tm_hour, stTime.tm_min, stTime.tm_sec); } printf("\n\n"); fclose(fp); @@ -135,13 +139,13 @@ int view() int menu(char* szNickname) { if (szNickname && strlen(szNickname) > 0) - printf("Hi! %s! ", szNickname); - printf("Welcome to play 'Guess Number'!\n"); + printf("你好!%s!", szNickname); + printf("欢迎来玩『 猜数字 』!\n"); printf("\n"); - printf("1. Begin to Play!\n"); - printf("2. View the Record!\n"); - printf("3. Change Nickname!\n"); - printf("4. Quit the Game!\n"); + printf("1. 开始游戏!\n"); + printf("2. 查看历史!\n"); + printf("3. 更改昵称!\n"); + printf("4. 退出游戏!\n"); printf("\n"); return getch();