liveBook · Manning

Chapter 8: C library functions

What you will learn in chapter 8 of Modern C, Third Edition

Introduces the C library as a portable set of everyday programming tools and explains how its specified API can separate compiler and library implementations.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces the C library as a portable set of everyday programming tools and explains how its specified API can separate compiler and library implementations.

Key terms: C library, C language, interfaces, semantics, portability, application programming interface (API), compiler implementation, library implementation

8.1 General properties of the C library and its functions

This section distinguishes two purposes of C library functions and shows how one function can serve both.

Key terms: platform abstraction layer, basic tools, fixed interface, printf, snprintf, puts, formatting phase, output phase

8.1.1 Headers

This subsection explains that C library headers group interface descriptions for library features, chiefly functions.

Key terms: header file, interface descriptions, C library

8.1.2 Interfaces

This subsection explains that C library function interfaces may be implemented as function-like macros and sets a limited approach to pointer-valued interfaces.

Key terms: interfaces, function-like macros, textual replacements, side effects, pointer arguments, known pointers, nullptr, error condition

8.1.3 Error checking

This section explains how to recognize C library failures, report them, and handle the library’s error state.

Key terms: return value, special value, error, success, puts, EOF, perror, exit, fail fast, errno

8.1.4 Bounds-checking interfaces

This section explains why C offers optional bounds-checking library interfaces, how programs enable them, and what their naming and failure behavior imply.

Key terms: buffer overflow, bounds-checking interfaces, runtime constraint violation, Annex K, __STDC_LIB_EXT1__, __STDC_WANT_LIB_EXT1__, _s, printf_s, reserved

8.1.5 Platform preconditions

Explains how to make unavoidable platform requirements explicit and reject unsupported builds at compile time.

Key terms: portability, execution platform, code preconditions, preprocessor conditional, #if, #endif, #error, #warning, unknown identifiers, static_assert

8.2 Integer arithmetic

This section introduces C library interfaces for integer arithmetic, checked operations, and bit properties, emphasizing their results and exceptional cases.

Key terms: abs, div, quot, rem, ckd_add, checked arithmetic, <stdckdint.h>, overflow, least significant bits, <stdbit.h>

8.3 Numerics

This section introduces type-generic numerical functions and explains why programmers should generally use library implementations rather than replace them.

Key terms: <math.h>, <tgmath.h>, type-generic macros, numerical precision, processor-specific instructions, numerical functions

8.4 Input, output, and file manipulation

Introduces two <stdio.h> output functions by contrasting basic string output with formatted output.

Key terms: <stdio.h>, puts, printf, end-of-line character

8.4.1 Unformatted text output

Introduces single-character output and stream-based unformatted output, including error reporting, opaque FILE streams, standard output streams, and newline handling.

Key terms: putchar, EOF, FILE*, stream, opaque type, fputs, fputc, stdout, stderr, puts

8.4.2 Files and streams

This section explains how to attach files to C streams, choose opening modes, handle opening failures, and reassociate an existing stream.

Key terms: fopen, stream, perror, mode argument, base modes, append, update mode, fopen_s, freopen_s, errno_t

8.4.3 Text I/O

This section explains buffering and flushing of text output, conversions between program text and external text, and why text lines should avoid trailing whitespace.

Key terms: buffered, flushed, fflush, fclose, line buffering, puts, text input and output, converts data, character encodings, end-of-line

8.4.4 Formatted output

This section explains how to choose and construct formatted-output conversions, match them to arguments, and use formats suited to display or later readback.

Key terms: printf, fprintf, trailing arguments, format specifiers, modifier, undefined behavior, format specification, flags, width, precision

8.4.5 Unformatted text input

This section introduces unformatted text input functions and explains how to distinguish a failed read from reaching end-of-file.

Key terms: fgetc, fgets, stdin, int, EOF, feof, failed read, gets, buffer overflow

8.5 String processing and conversion

This section explains portable character handling, string-to-number conversion, and the string-search operations used in a simplified strtoul implementation.

Key terms: integer character constants, <ctype.h>, classifiers, toupper, tolower, octal value, hexadecimal value, execution character set, strtoul, base

8.5.1 Portability of string processing

This subsection explains why changes to C number syntax can make string-to-number conversion unreliable for finding number boundaries or scanning text derived from number literals.

Key terms: string-conversion functions, hexadecimal floating-point literals, 0b, strtol, formatted input, digit separator, number literals, strtoull, ULLONG_MAX

8.6 Time

This section explains C’s calendar-time representations, conversions, text formatting, and clocks for finer-resolution or processing-time measurements.

Key terms: calendar times, struct tm, time_t, tm_mon, tm_mday, tm_year, time(0), difftime, double, mktime

8.7 Runtime environment settings

This section explains how a C program reads runtime environment variables and controls its locale setting.

Key terms: environment list, environment variables, getenv, getenv_s, maxsize, locale, "C" locale, setlocale, <locale.h>, category

8.8 Program termination and assertions

Explains how to end a C program while preserving cleanup, how termination handlers work, and how assertions support debugging but can be disabled for production.

Key terms: return from main, exit, cleanup, atexit, exit handler, function reference, quick_exit, at_quick_exit, _Exit, abort

8.9 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 7: Functions Chapter 9: Style →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.