I've searched the forums a bit but I couldn't really find anything relative to this matter.
I'm relatively new to C++, and I always used cout and cin. But I find the syntax style a bit off, so I was searching for alternatives and found scanf, sscanf and well printf.
Now I think I understand how scanf works, but what I don't understand is why it continues to execute the program when It couldn't find the type it was searching for in the first place.
Here's the code.
int main(){
int players;
int sblind;
int tchips;
char uname[16];
do{
printf( "How many players are going to enter the game? (min = %d, max = %d)\nPlayers: ", MIN_PLAYERS, MAX_PLAYERS );
scanf( "%d[int]", &players );
} while( players < MIN_PLAYERS || players > MAX_PLAYERS );
do{
printf( "What will be the value of the small blind? (min = %d)\nSmall Blind: ", MIN_BLIND );
scanf( "%d", &sblind );
} while( sblind < MIN_BLIND );
do{
printf( "How many chips does each player begin with? (min = %d)\nChips: ", MIN_BLIND * MIN_CHIPSMP );
scanf( "%d", &tchips );
} while( tchips < MIN_BLIND * MIN_CHIPSMP );
CTable table (players);
printf( "\n" );
for( int i = 1; i <= players; i++ ){
do{
printf( "What is the name of player %d? (max length = %d)\nUsername: ", i, MAX_UNAMELEN );
} while( scanf( "%s", &table.players[i].uname ) > MAX_UNAMELEN );
}
return 0;
}
Now it works when I just enter the value scanf expects, but how can I prevent invalid input?