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
|
|
@ -23,7 +23,7 @@
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
#define VERSION 0.0.2
|
#define VERSION 0.0.3
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
// First the boilerplate stuffs
|
// First the boilerplate stuffs
|
||||||
|
|
|
||||||
16
ui_vt100.c
16
ui_vt100.c
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
|
||||||
#define BOARD_WIDTH_CHARS ( 3 * BOARD_WIDTH + 6 )
|
#define BOARD_WIDTH_CHARS ( 3 * BOARD_WIDTH + 6 )
|
||||||
|
|
@ -131,7 +132,20 @@ int askColumn(
|
||||||
printf( "Wher player %d put? ", board.player );
|
printf( "Wher player %d put? ", board.player );
|
||||||
#endif /* ONLYPUT */
|
#endif /* ONLYPUT */
|
||||||
printf( "\033[K" ); // clear everything after cursor
|
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;
|
column -= FIRST_NUMBER;
|
||||||
if( column >= 0 && column < BOARD_WIDTH )
|
if( column >= 0 && column < BOARD_WIDTH )
|
||||||
#ifndef ONLYPUT
|
#ifndef ONLYPUT
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue