Page t005, go to NEXT,
PREVIOUS, INDEX
Input and Output
Introduce I/O early, so we can run programs and see something
happen :-)
Example
#include <stdio.h>
/* Read and print three floating point numbers */
int main()
{
float a, b, c;
/* Input */
scanf ("%f %f %f", &a, &b, &c);
/* Output */
printf ("%f, %f, %f\n", a, b, c);
return (0);
}
- stdio.h is header file containing definitions
of macros and variables used by the I/O system
- a, b and
c are floating point variables
- scanf reads formatted input from
stdin, i.e. the keyboard
- "%f" denotes format conversion to float
- "&" denotes the address of the variable to be
passed to the input function (and not a copy of the value)
- printf prints formatted output to
stdout, i.e. the screen
- "\n" denotes the end-of-line character
C Course, 15-jan-1997,
Peter Klok,
pfk@hef.kun.nl