Important Notes in C:
scanf() Returned Value
scanf() will return 0
If the input the user written doesn't match the format specifier%i or %d or %c
or whatever
like ( int was expected but it was char instead)
In this example:
("enter number %i and character %c", %num, %char);
- If num was integer and char was character scanf() will return 2.
- If one was wrong and the other right scanf() will return 1.
- If nothing was right and data types entered conflicted
with format specifiers scanf() will return 0.
Clearing the buffer
If we want to clear the buffer in memory of I/O device after entering character we should make a space before char placeholder (" %c") or use the following snippet
while(getchar() != '\n')