INFO505 Programmation C
Loading...
Searching...
No Matches
test-scanf.c
1#include <stdio.h>
2#include <stdlib.h>
3
4int main()
5{
6int colonne;
7char str[ 8 ];
8while ( 1 ) {
9 printf( "(g)auche, (d)roite ou (0-14) colonne: " );
10 if ( scanf( "%7s", str ) == 1 ) {
11 if ( str[ 0 ] == 'g' ) { printf( "gauche\n" ); }
12 else if ( str[ 0 ] == 'd' ) { printf( "droite\n" ); }
13 else {
14 colonne = atoi( str );
15 printf( "colonne=%d\n", colonne ); }
16 }
17}
18 return 0;
19}