Home > Back-end >  The second the scanf why this simple C program doesn't work?
The second the scanf why this simple C program doesn't work?

Time:11-20

 # include & lt; stdio.h> 

Int main ()
{
Int a;
Char z;
//printf (" a ");
The scanf (" % d ", & amp; A);
Printf (" b ");
//z=getchar ();
The scanf (" % c ", & amp; Z);
Printf (" c ");

return 0;
}

CodePudding user response:

First the scanf you the input value is assigned to a, then b printed character how there may be the result of
No matter what you input, printed characters b ah, the same to the second the scanf, middle haven't empty buffer

CodePudding user response:

You want the effect should be the following



Int main ()
{
Int a;
Char z;
The scanf (" % d ", & amp; A);
Printf (" % d \ n ", a);
//printf (" b ");
//z=getchar ();
The fflush (stdin);
The scanf (" % c ", & amp; Z);
Printf (" % c ", z);
return 0;
}

CodePudding user response:

Work, the second is the scanf received '\ n', '\ n' % c matching, this after an input in the input buffer '\ n'
  • Related