printf is ouput is being destyoryed by a “\n” after I run scanf. I am attempting to use.
scanf ("%*c");
to chomp the “\n” but its not working… here is the code
printf("Enter char float int char:", char4, deci2, num2, char5);
scanf ("%c %f %d %c", &char4, &deci2, &num2, &char5);
scanf ("%*c");
printf("You entered: '%c' %.3f %d '%c' " ,char4 ,deci2, num2, char5 );
and it outputs to
Enter char int char float:a 5 a 5.5
You entered: 'a' 5 'a' 5.500
Enter char float int char:a 5.5 6 b
You entered: '
' 0.000 0 ''
The line
is picking up the stray newline left in the input buffer from your previous
scanfcall. You can work around that by putting a space in front of the first%c:This will tell
scanfto skip over any leading whitespace (blanks, newlines, tabs, etc.) before reading the next non-whitespace character.The line
is a bit of a head-scratcher; it won’t cause any problems (the excess arguments are evaluated, but otherwise ignored), but it looks wrong, and indicates some confusion.