Fixed the scanf funkyness in vt100 mode
This commit is contained in:
parent
f80a7273a2
commit
4f25f66495
2 changed files with 16 additions and 2 deletions
16
ui_vt100.c
16
ui_vt100.c
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
#include "ui.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "macros.h"
|
||||
|
||||
#define BOARD_WIDTH_CHARS ( 3 * BOARD_WIDTH + 6 )
|
||||
|
|
@ -131,7 +132,20 @@ int askColumn(
|
|||
printf( "Wher player %d put? ", board.player );
|
||||
#endif /* ONLYPUT */
|
||||
printf( "\033[K" ); // clear everything after cursor
|
||||
scanf( "%d", &column );
|
||||
fflush( stdout );
|
||||
column = -1;
|
||||
for( char ch = '0'; ch != '\n'; read( STDIN_FILENO, &ch, 1 ) ){
|
||||
if( ch >= '0' && ch <= '9' ){
|
||||
if( column == -1 )
|
||||
column = 0;
|
||||
else
|
||||
column *= 10;
|
||||
if( column >= 0 )
|
||||
column += ( int )( ch - '0' );
|
||||
} else {
|
||||
column = -2;
|
||||
}
|
||||
}
|
||||
column -= FIRST_NUMBER;
|
||||
if( column >= 0 && column < BOARD_WIDTH )
|
||||
#ifndef ONLYPUT
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue