1 /* play_again0.c 2 * purpuse: ask if user wants another play 3 * returns: 0 -> yes , 1 -> no 4 */ 5 6 #include <stdio.h> 7 #include <stdlib.h> 8 #include <termios.h> 9 10 #define QUESTION "Do you want another play?" 11 12 int get_response(char *); 13 14 int main() 15 { 16 int response ; 17 response = get_response(QUESTION); 18 return response ; 19 } 20 21 int get_response(char * qiz) 22 { 23 printf("%s(y/n)" , qiz); 24 while(1) 25 { 26 switch(getchar()) 27 { 28 case 'y': 29 case 'Y': return 0 ; 30 case 'n': 31 case 'N': return 1 ; 32 } 33 } 34 }
本文介绍了一个简单的C语言程序,用于在游戏结束后询问玩家是否想重新开始游戏。程序通过命令行界面接收用户的输入,并根据用户的回答返回不同的值来指示是否进行重玩。
154

被折叠的 条评论
为什么被折叠?



