scanf is the input equivalent of printf.
int scanf(char *format, arg1, arg2, ...)
scanf reads characters from the standard input, interprets them according to the specifications in format, and stores the results through the remaining arguments. All arguments except the format argument must be a pointer, which would hold the input.
scanf stops when it exhausts its format string, or when some input fails to match the control specification. It returns the number of successfully matched and assigned input items.
To read a float and an int value:
int i; float f; char word[20]; scanf("%i%f%s", &i, &f, word);
We don’t use & with array word since an array name is a pointer. scanf ignores blanks and tabs in its format string.
A common error while using scanf involves missing the & symbol. This won’t be detected at compile-time, so we need to be careful about it.
We also have sscanf which reads from a string instead of the standard input:
int sscanf(char *str, char *format, arg1, arg2, ...)