Micron Document
The C Programming Language, Ansi C


← Prev · 158/277 · Next →

Many programs read only one input stream and write only one output stream; for such programs, input and output with getchar, putchar, and printf may be entirely adequate, and is certainly enough to get started. This is particularly true if redirection is used to connect the output of one program to the input of the next. For example, consider the program lower, which converts its input to lower case:

#include <ctype.h>

main() /* lower: convert input to lower case*/
{
int c

while ((c = getchar()) != EOF)
putchar(tolower(c));
return 0;
}

The function

tolower

is defined in

ctype.h>

; it
converts an upper case letter to lower case, and returns other characters
untouched. As we mentioned earlier, functions'' like

getchar

and

putchar

in

stdio.h>

and

tolower

in

ctype.h>

are often macros, thus avoiding the overhead of a
function call per character. We will show how this is done in

Section 8.5

. Regardless of how the

ctype.h>

functions are implemented on a given machine,
programs that use them are shielded from knowledge of the character set.

Exercise 7-1. Write a program that converts upper case to lower or lower case to upper, depending on the name it is invoked with, as found in argv[0].

The output function

printf

translates internal values to characters.
We have used

printf

informally in previous chapters. The description
here covers most typical uses but is not complete; for the full story, see

Appendix B

.

int printf(char *format, arg1, arg2, ...);

printf

converts, formats, and prints its arguments on the standard
output under control of the

format

. It returns the number of
characters printed.

The format string contains two types of objects: ordinary characters, which are copied to the output stream, and conversion specifications, each of which causes conversion and printing of the next successive argument to printf. Each conversion specification begins with a % and ends with a conversion character. Between the % and the conversion character there may be, in order:

A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument. A minus sign, which specifies left adjustment of the converted argument.