C_and_CPP 板


LINE

#include <stdio.h> #include <stdlib.h> #include<time.h> #include <string.h> //void number(); void history_brd(); void view_history(); int main() { char history;//是否加入歷史排行榜的選項 char brd_choice;//是否觀看歷史排行榜的選項 int y,w_t=0,l_t=0; do{ int s; int w=0,l=0,n1; printf("請輸入你要的局數(一場)\n"); scanf("%d",&n1); n1=(n1+1)/2; do{ srand(time(NULL)); int n=rand()%3+1; printf("%d",n); printf("(1剪刀 (2石頭 (3布\n"); printf("請輸入你的選擇\n"); scanf("%d",&s); if(n==1&&s==1) { printf("你出剪刀!!\n"); printf("電腦出剪刀\n"); printf("平手唷!!!\n"); } else if(n==1&&s==2) { printf("你出石頭!!\n"); printf("電腦出剪刀\n"); printf("你贏囉!!\n"); w=w+1; } else if(n==1&&s==3) { printf("你出布\n"); printf("電腦出剪刀\n"); printf("你輸囉!!!\n"); l=l+1; } else if(n==2&&s==2) { printf("你出石頭!!\n"); printf("電腦出石頭\n"); printf("平手唷!!!\n"); } else if(n==2&&s==1) { printf("你出剪刀!!\n"); printf("電腦出石頭\n"); printf("你輸囉!!\n"); l=l+1; } else if(n==2&&s==3) { printf("你出布!!\n"); printf("電腦出石頭\n"); printf("你贏囉!!!\n"); w=w+1; } else if(n==3&&s==3) { printf("你出布!!\n"); printf("電腦出布\n"); printf("平手唷!!!\n"); } else if(n==3&&s==2) { printf("你出石頭!!\n"); printf("電腦出布\n"); printf("你輸囉!!\n"); l=l+1; } else if(n==3&&s==1) { printf("你出剪刀!!\n"); printf("電腦出布\n"); printf("你贏囉!!!\n"); w=w+1; } }while( w<n1 && l<n1); if(w==n1) { printf("你贏了此場\n"); w_t=w_t+1; } else if(l==n1) { printf("你輸了此場\n"); l_t=l_t+1; } printf("想繼續玩請按1\n"); scanf("%d",&y); printf("你目前的戰績為%d勝%d敗\n",w_t,l_t); }while(y==1); printf("你的最終戰績為%d勝%d敗\n",w_t,l_t); printf("\n是否要加入歷史排行榜?(y/n)"); fflush(stdin); scanf("%c",&history); if(history == 'y') { history_brd(); printf("是否觀看歷史排行榜 ? (y/n)"); fflush(stdin); scanf("%c",&brd_choice); if(brd_choice == 'y') { view_history(); } } system("pause"); return 0; } void history_brd(int w_t,int l_t) { FILE *out; char name[50]; time_t timep; time (&timep); out = fopen("board.bin","a+"); printf("\n請輸入你的姓名 : "); scanf("%s",name); fprintf(out,"%s總共在猜拳遊戲中%d勝%d敗 %s",name,w_t,l_t,ctime(&timep)); fclose(out); system("pause"); } void view_history() { char list[200]; FILE *inp; inp = fopen("board.bin","a+"); system("cls"); //while(!feof(inp)) while(fscanf(inp,"%s", &list) != EOF) { printf("%s\n",list); memset(list,0,sizeof(char)*200); fgets(list,199,inp); printf("%s\n",list); } fclose(inp); system("pause"); } 這個遊戲我之前可以執行 沒想到存檔後 要再次執行出現這個 [Linker error] undefined reference to `history_brd()' ld returned 1 exit status 請問這個怎麼改 感謝萬分!! --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.172.86.214
1F:→ tsaiminghan:fopen 讀檔時,用的應該不是a+,還有程式碼太長時 04/04 12:42
2F:→ tsaiminghan:用公告的網頁來貼程式碼 04/04 12:43
3F:→ MOONRAKER:每一種組合都恭喜一次,好累的程式 XD 04/04 12:52
4F:→ a1013944:歐 謝謝指教 新手@@慢慢學習 04/04 12:53
5F:→ MOONRAKER:弄個勝負matrix不就好了 沒人教你啊? 04/04 13:08
6F:→ firedcf:非常不專業的改了九次.最後發現srand前面加上 // 就過了XD 04/04 15:30
7F:→ firedcf:忘了說... fopen的a+我有改成 ab XD 04/04 15:31
8F:→ tsaiminghan:所以那邊是有什麼問題啊? 04/04 15:31
9F:→ firedcf:因為不專業,所以我也不知道XD .. >///< .. 04/04 15:50
10F:→ tsaiminghan:剛剛發現一個無關的問題,不用包string.h,沒用到 04/04 16:10







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:BabyMother站內搜尋

TOP