printf |
Formally:
int printf(char *format, ...) |
printf( format string, argument list ); |
Example |
printf("The littlest=%d the largest=%d\n", little, large); |
The littlest=3 the largest=10 |
printf Conversions |
argument type; printed as | |
%d, %i | int; decimal number |
%c | int; single character |
%s | char *; characters from string till \0 or number of characters given by precision |
%f | double; m.dddddd where number of ds given by precision (not float) |
%e, %E | double; scientific notation, m.ddddddexx (ds given by precision) |
Example |
scanf |
int scanf(char *format, ...) |
scanf( format string, argument list ); |
scanf("%d%f", &first, &second); |
scanf("%d", n); /* WRONG */ scanf("%d", &n); /* right */ |
Example |
Suppose we want to scan dates of the form "25/09/1965" and "25 Sep 1965" then we use, respectively,
int day, month, year; scanf("%d/%d/%d", &day, &month, &year); |
int day, year; char monthname[20]; scanf("%d %s %d", &day, monthname, &year); |
scanf Conversions |
input data; argument type | |
%d | decimal integer; int |
%e, %f | floating point; float (not double) |
%c | characters; char * |
%s | character string (not quoted); char * pointing to an array of characters large enough for the string and terminating with \0 |
...previous | up (conts) | next... |