Skip to the content.

Chapter 4: Functions and Program Structure

Exercises from “The C Programming Language” (2nd Edition) by Brian W. Kernighan and Dennis M. Ritchie.

Exercises

# Description Source
4-01 strrindex(s, t): rightmost occurrence of t in s -
4-02 Extend atof for scientific notation -
4-03 Add modulus and unary minus to calculator -
4-04 Print top, duplicate, swap stack elements -
4-05 Add math functions (sin, exp, pow) -
4-06 Add variables (single-letter names) -
4-07 ungets(s): push string back on input -
4-08 Modify getch/ungetch for single character -
4-09 Handle pushed-back EOF -
4-10 Use getline instead of getchar -
4-11 Modify getop to avoid ungetch -
4-12 Recursive itoa -
4-13 Recursive reverse(s) -
4-14 Macro swap(t, x, y) -

Compilation

gcc -Wall -Wextra -o exercise exercise.c
./exercise