コード例 #1
0
ファイル: play_again4.c プロジェクト: yku/unix_systems
/*
 * y/n以外の回答を無視する。yなら0,nなら1を返す。
 */
int get_response(char* str, int tries)
{
    int input;
    printf("%s (y/n) ?", str);
    fflush(stdout);
    while(1){
        sleep( SLEEPTIME );
        input = tolower( get_ok_char() );
        if( input == 'y' ) return 0;
        if( input == 'n' ) return 1;
        if( tries-- == 0 )  return 2;
        BEEP;
    }
}
コード例 #2
0
ファイル: play_again3.c プロジェクト: acgtyrant/UULP
extern int get_response(char *question) {
  int c;
  printf("%s (y/n)?", question);
  fflush(stdout);
  while (true) {
    sleep(SLEEPTIME);
    c = tolower(get_ok_char());
    if (c != EOF)
      putchar(c);
    if (c == 'y')
      return 0;
    if (c == 'n')
      return 1;
    if (maxtries-- == 0)
      return 2;
    BEEP;
  }
}
コード例 #3
0
ファイル: play_again4.c プロジェクト: iCun/LinuxProgramming
int get_response(char *question, int maxtries) {
	/* 
	 * purpose: ask a question and wait for a y/n answer or timeout
	 *  method: use getchar and complain about non-y/n input
	 * returns: 0=>yes, 1=>no
	 */
	int input;
	printf("%s (y/n)?", question);
	fflush(stdout);
	while(1) {
		sleep(SLEEPTIME);
		input = tolower(get_ok_char());
		if (input == 'y') return 0;
		if (input == 'n') return 1;
		if (maxtries-- == 0) return 2;
		BEEP;
	}
}
コード例 #4
0
ファイル: playagain.c プロジェクト: maxjazz/moley
int get_response (char *question, int maxtries)
{
  int input;
  printf("%s (y/n)\n", question );
  fflush(stdout);
  while (1)
  {
    sleep(SLEEPTIME);
    input = tolower(get_ok_char());
  //  printf ("Input is %d, number of tries os %d\n", input, maxtries);
    if (input == 'y')
      return 0;
    if (input == 'n')
      return 1;
    if (maxtries-- == 0 )
      return 2;
    BEEP;
  }
}
コード例 #5
0
ファイル: play_again.c プロジェクト: dantin/shadow
int get_response( char *question, int maxtries )
{
  int input;

  printf( " %s(y/n)?", question );
  fflush( stdout );
  while( 1 ) {
    sleep( SLEEPTIME );
    input = tolower( get_ok_char() );

    if( input == 'y' ) {
      return 0;
    }
    if( input == 'n' ) {
      return 1;
    }
    if( maxtries-- == 0 ) {
      return 2;
    }
    BEEP;
  }
}
コード例 #6
0
get_response( char *question , int maxtries)
/*
 * purpose: ask a question and wait for a y/n answer or timeout
 *  method: use getchar and complain about non-y/n input
 * returns: 0=>yes, 1=>no
 */
{
    int	input;

    printf("%s (y/n)?", question);			/* ask		*/
    fflush(stdout);					/* force output	*/
    while ( 1 ) {
        sleep(SLEEPTIME);			/* wait a bit	*/
        input = tolower(get_ok_char());         /* get next chr */
        if ( input == 'y' )
            return 0;
        if ( input == 'n' )
            return 1;
        if ( maxtries-- == 0 )			/* outatime?	*/
            return 2;			/* sayso	*/
        BEEP;
    }
}
コード例 #7
0
ファイル: play_again3.c プロジェクト: LXiong/blog_tmp
int
get_response(char *question, int maxtries)
{
	int input;

	printf("%s (y/n)? ", question);
	fflush(stdout);
	while (1) {
		sleep(SLEEPTIME);
		switch (input = get_ok_char()) {
		case 'y':
		case 'Y':
			putchar('\n');
			return 0;
		case 'n':
		case 'N':
			putchar('\n');
			return 1;
		}
		if (maxtries-- == 0)
			return 2;
		BEEP;
	}
}