求做C程序文件菜单
这是我做的东西,你的游戏程序必须返回一个成绩的结果体数据,可以满足你的所有要求,不过菜单是输入选择性的,不是图形界面。粘贴上来格式有问题,自己调整。在VS2005中编译通过,运行成功。程序如下:#include#include#includetypedefstruct{charname[255];longscore;}User;voidMenu(){printf("========================madeby小恩=====================\n");printf("==\t\t\ta:startgame\t\t\t==\n");printf("==\t\t\t...全部
这是我做的东西,你的游戏程序必须返回一个成绩的结果体数据,可以满足你的所有要求,不过菜单是输入选择性的,不是图形界面。粘贴上来格式有问题,自己调整。在VS2005中编译通过,运行成功。程序如下:#include#include#includetypedefstruct{charname[255];longscore;}User;voidMenu(){printf("========================madeby小恩=====================\n");printf("==\t\t\ta:startgame\t\t\t==\n");printf("==\t\t\tb:showorder\t\t\t==\n");printf("==\t\t\tc:quitgame\t\t\t==\n");printf("==========================================================\n");}charchoise(){charch;printf("Inputyourchoice(a~c):");while(ch=getchar()){while('\n'!=getchar());if(ch>'c'||chscore));//成绩getchar();printf("Inputyourname(Lessthan254letters:)");scanf("%s",pSean->name);getchar();return;}voidsaveData(Usersean){FILE*fp;longi=0,fPos=0;intflag=3;intlth=sizeof(User);Userbuf;size_tsz;if(fopen_s(&fp,"F:\\game_data。
dat","r+b")){printf("Can'topenF:\\game_data。dat!\n");exit(1);}while(sz=fread(&buf,lth,1,fp)){if(0==strcmp( , )){if( ore ore)continue;else{fseek(fp,(-1)*(lth),SEEK_CUR);fwrite(&sean,lth,1,fp);fseek(fp,0,SEEK_CUR);sean=buf;}}break;case2://新玩家fseek(fp,0,SEEK_SET);while(fread(&buf,lth,1,fp)){if( ore> ore)continue;fseek(fp,-1*lth,SEEK_CUR);fwrite(&sean,lth,1,fp);fseek(fp,0,SEEK_CUR);sean=buf;}fwrite(&sean,lth,1,fp);break;case3://以前数据文件无数据fwrite(&sean,lth,1,fp);break; ("SomethingErrorwhensavedata!\n");break;}fclose(fp);printf("SaveDatainF:\\game_data。
dat\n");return;}voidshowOrder(intmax){FILE*fp;intlth=sizeof(User);intn=0;Userbuf;if(fopen_s(&fp,"F:\\game_data。
dat","r")){printf("Can'topenF:\\game_data。dat!\n");exit(1);}printf("Thisistheorder!\n");printf("__________Name\t__________Score\t__________No。
__________\n");while(fread(&buf,lth,1,fp))printf("__________%s\t__________%d\t__________%d__________\n", , ore,++n);fclose(fp);return;}main(){charitem,name[255];Usersean;memset(name,0,sizeof(name));Menu();while('c'!=(item=choise())){switch(item){case'a':system("cls");game(&sean);saveData(sean);Menu();break;case'b':system("cls");showOrder(10);Menu();break; ("SomethingError\n");break;}}Byebye();}。
收起