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灯, 水草

请输入看板名称,例如:Soft_Job站内搜寻

TOP