/* * 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; } }
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; } }
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; } }
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; } }
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; } }
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; } }
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; } }