Understanding Unix/Linux Programming-用户程序:play_again0

本文介绍了一个简单的C语言程序,用于在游戏结束后询问玩家是否想重新开始游戏。程序通过命令行界面接收用户的输入,并根据用户的回答返回不同的值来指示是否进行重玩。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 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  }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值