Input integer, float and character values using one scanf() statement in C
We have to read tree values: integer, float and then character using only one scanf() function and then print all values in separate lines.
Example:
Input:
Input integer, float and character values: 10 2.34 X
Output:
Integer value: 10
Float value: 2.340000
Character value: X
Before moving to the program, please consider the scanf() statement,
scanf ("%d%f%*c%c", &ivalue, &fvalue, &cvalue);
Here, %*c is used to skip the character to store character input to the character variable, almost all time, character variable’s value will not be set by the given value because of the "ENTER" or "SPACE" provided after the float value, thus, to set the given value, we need to skip it.
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer