I know about the difference and the advantage/disatvantage of using scanf and fgets.
I don't understand the relations between printf and this two C standard functions.
I have this simple code:
void print_choice(char * list, char * choice)
{
/* check parameters */
if(!list || !choice)
return;
printf("list of users: %s\n", list);
printf("Choice -- ? ");
/* scanf("%s", &choice); */
/* fgets(choice, 20, stdin); */
}
int main()
{
char choice[20];
char * list = "marco:dario:roberto:franco";
print_choice(list, choice);
printf("choice = %s\n", choice);
return 0;
}
if I use fgets
, printf print the result correctly on stdout;
If I use scanf
, printf` doesn't print anything on stdout.
Why this behaviour?