take a look at this piece of code...
Code:
#include <stdio.h>
int main( void )
{
int i = 0, c = 0, sent = 0;
char str[ 30 ];
printf( "Choose ( 0 to this, 1 do that ) : " );
scanf( "%d", &sent );
if( sent )
;/* do stuff */
else {
printf( "Please input a string of text : \n" );
while( ( c = getchar() ) != '\n' )
str[ i++ ] = c;
str[ i ] = '\0';
printf( "The string entered was : \n" );
puts( str );
}
return 0;
}
if the sentinel value is 0 it seems that getchar() takes
the newline char that i inputed in order to scanf() the sentinel
value.
I thought that scanf() doesn't leave the newline char in stdin,
so that i don't have to fflush() it.
Any comments on that ?
trekker