[問題] 這個遊戲小錯誤

看板C_and_CPP (C/C++)作者 (ㄚ春)時間16年前 (2009/04/04 11:51), 編輯推噓0(0010)
留言10則, 4人參與, 最新討論串1/2 (看更多)
#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

04/04 12:42, , 1F
fopen 讀檔時,用的應該不是a+,還有程式碼太長時
04/04 12:42, 1F

04/04 12:43, , 2F
用公告的網頁來貼程式碼
04/04 12:43, 2F

04/04 12:52, , 3F
每一種組合都恭喜一次,好累的程式 XD
04/04 12:52, 3F

04/04 12:53, , 4F
歐 謝謝指教 新手@@慢慢學習
04/04 12:53, 4F

04/04 13:08, , 5F
弄個勝負matrix不就好了 沒人教你啊?
04/04 13:08, 5F

04/04 15:30, , 6F
非常不專業的改了九次.最後發現srand前面加上 // 就過了XD
04/04 15:30, 6F

04/04 15:31, , 7F
忘了說... fopen的a+我有改成 ab XD
04/04 15:31, 7F

04/04 15:31, , 8F
所以那邊是有什麼問題啊?
04/04 15:31, 8F

04/04 15:50, , 9F
因為不專業,所以我也不知道XD .. >///< ..
04/04 15:50, 9F

04/04 16:10, , 10F
剛剛發現一個無關的問題,不用包string.h,沒用到
04/04 16:10, 10F
文章代碼(AID): #19rjaiBV (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #19rjaiBV (C_and_CPP)