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

 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  }
原文地址:https://www.cnblogs.com/NJdonghao/p/5286492.html