Chapter 7: Input and Output

page 151

By ``Input and output facilities are not part of the C language itself,'' we mean that things like printf are just function calls like any other. C has no built-in input or output statements. For our purposes, the implications of this fact--that I/O is not built in--is mainly that the compiler may not do as much checking as we might like it to. If we accidentally write

	double d = 1.23;
	printf("%d\n", d);
the compiler says, ``Hmm, a function named printf is being called with a string and a double. Okay by me.'' The compiler does not (and, in general, could not even if it wanted to) notice that the %d format requires an int.

Although the title of this chapter is ``Input and Output,'' it appears that we'll also be meeting a few other routines from the standard library.

If you start to do any serious programming on a particular system, you'll undoubtedly discover that it has a number of more specialized input/output (and other system-related) routines available, which promise better performance or nicer functionality than the pedestrian routines of C's standard library. You should resist the temptation to use these nonstandard routines. Because the standard library routines are defined precisely and ``exist in compatible form on any system where C exists,'' there are some real advantages to using them. (On the other hand, when you need to do something which C's standard library routines don't provide, you'll generally turn to your machine's system-specific routines right away, as they may be your only choice. One common example is when you'd like to read one character immediately, without waiting for the RETURN key. How you do that depends on what system you're using; it is not defined by C.)

section 7.1: Standard Input and Output

section 7.2: Formatted Output--Printf

section 7.3: Variable-length Argument Lists

section 7.4: Formatted Input--Scanf

section 7.5: File Access

section 7.6: Error Handling--Stderr and Exit

section 7.7: Line Input and Output

section 7.8.1: String Operations

section 7.8.2: Character Class Testing and Conversion

section 7.8.3: Ungetc

section 7.8.4: Command Execution

section 7.8.5: Storage Management

section 7.8.6: Mathematical Functions

section 7.8.7: Random Number Generation


Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995, 1996 // mail feedback