Bringing Information into C Programs
has a complement in the
reads information into a program.
printf("How many students? ");
scanf("%d", &num_stud );
printf("There are %d students.\n", num_stud );
in that it takes a format string and then zero
or more arguments identifying where to put the information.
format string for
the format for all inputs to be read by that call.
So if you have several variables being read by the same call to
, you'll have several format specifiers (like the
) in the format string.
As in this example, we rarely have anything except the format
specifiers in a
indicates that we'll be expecting a decimal integer
much as it did in
Another thing to notice is that we must specify a variable as the place
to put the result; we can't (normally) use a more complicated expression.
Finally, notice that we precede the variable name by the character
For now, just remember that when you are using
you need to precede
any numeric variables by an ampersand (
(The real reasons will become clear in Parts