14 More involved processing and I/O

 

This chapter covers

  • Working with pointers
  • Formatting input
  • Handling extended character sets
  • Input and output with binary streams
  • Checking errors and cleaning up

Now that we know about pointers and how they work, we will shed new light on some C library features. C’s text processing is incomplete without pointers, so we will start this section with an elaborated example in section 14.1. Then we will look at functions for formatted input (section 14.2); these require pointers as arguments, so we necessarily delayed their presentation until now. A whole new series of functions is then presented to handle extended character sets (section 14.3) and binary streams (section 14.6). We round out this section and the entire level with a discussion of clean error handling (section 14.6)).

14.1 Text processing

As a first example, consider the following program, which reads a series of lines, each with several numbers from stdin, and writes these same numbers in a normalized way to stdout as comma-separated hexadecimal numbers:

numberline.c

14.2 Formatted input

14.3 Extended character sets

14.4 UTF character encodings

14.5 Restartable text conversion

14.6 Binary streams

Summary