Introduction
The documents linked to this page constitute the "lectures" of a one-semester, introductory
course in the C programming language. I created these documents myself and have used them in
programming classes at Vermont Technical College, where I am
an instructor. I am posting these documents on the web for public access under the terms of the
GNU Free Documentation License (GFDL).
Permission is granted to copy, distribute and/or modify this document (and the related
subordinate documents as described above) under the terms of the GNU Free Documentation License,
Version 1.1 or any later version published by the Free Software Foundation; with no invariant
sections, no front-cover texts, and no back-cover texts.
Lessons
This course covers all the major features of the C language: variables, types, expressions,
control flow, functions, arrays, pointers, strings, and structures. In addition, I cover a
number of other, minor topics. I have broken all of this material into 30 lessons along with
some supporting files. Each lesson builds on the previous lessons. I recommend that you read the
lessons in order. However, if you have some previous C experience, you may find it useful to
skip around. The first three lessons are designed to get you on board using a Unix system where
I assume you will be writing your programs. If you plan to work on a different operating system
or if you are familiar with Unix, you may be able to skip those lessons. The C related content
starts with Lesson #4.
When I last taught this course, the text associated with it was Stephen G. Kochan's
"Programming in ANSI C" (Revised edition, Sams Publishing, (C) 1994, ISBN=0-672-30339-6). You
could use any reasonable book on C to supplement this material. However, I have prepared specific reading assignments from Kochan's text to support each
of the lessons.
In addition to the lessons themselves, I have also prepared some sample programs to help
illustrate some points and to show the features of C in a larger context than is possible in the
lessons. In the list below, I show links to these samples as well as to the lesson text. Each
sample is associated with a particular lesson. You should review each sample after you've read
the corresponding lesson text.
- Lesson 1: Unix: Logging on/off. Mail, editing files, file
transfer.
- Lesson 2: Unix: Various useful Unix commands.
- Lesson 3: Unix: File system structure; file permissions.
- Lesson 4: The "Hello, World!" program.
- Lesson 5: The built-in arithmetic types. (printf_demo.c, types_demo.c )
- Lesson 6: Expressions and precedence. (prec.c)
- Lesson 7: Conditional expressions and if, if... else
statements.
- Lesson 8: Compound conditions and for loops. (Example 1: Prime numbers. prime.c)
- Lesson 9: while loops, do/while loops, and filter programs.
- Lesson 10: switch statements and if... else if... chains. (textstats.c), (Example 2: A filter program that detects white space. white.c)
- Lesson 11: Pseudo-code. (print_format.pcd)
- Lesson 12: Basic testing and debugging techniques.
- Lesson 13: Debugging using a debugger.
- Lesson 14: Functions: Terminology and basic structure.
- Lesson 15: Scope. Local (block) vs Global. (Example 3: A program to compute prime factors. prime_factors.c)
- Lesson 16: Duration. Static vs automatic. Rules for
initialization.
- Lesson 17: Spreading a program across multiple files. (Example 4: A library for integer math operations. imath.h, imath.c, imath_test.c)
- Lesson 18: Arrays: declaring, accesssing, initializing. (Example 5: Counting characters in a file. char_count.c)
- Lesson 19: Pointers: declaring, initializing, dereferencing.
- Lesson 20: How pointers and arrays interact. (Example 6: Sorting numbers. sort_int.c)
- Lesson 21: Passing pointers and arrays into functions.
- Lesson 22: Strings.
- Lesson 23: Standard library string handling functions. (Example 7: Library string functions. This example requires
curses. string_test.c)
- Lesson 24: File I/O. (Example 8:
Splitting files. filesplit.c)
- Lesson 25: Pointers to pointers and command line processing.
- Lesson 26: Structures: defining, accessing, initializing.
- Lesson 27: Interaction between structures, arrays, pointers,
and functions.
- Lesson 28: Preprocessor.
- Lesson 29: Bit manipulation operators.
- Lesson 30: typedef, const, and type conversion.
Other C features that I may write about at a later time include: enums, unions, bit fields,
internationalization (i18n), and changes introduced in C99 (relative to C89/90). In addition, I
would like to create a few more examples or perhaps elaborate a bit on some of the existing
examples.
Links
The links below are of general interest.
- I have a page of links to other C related materials on the web (sketchy
at this time).
- Although I run this course on a Unix system, you might prefer to do your program development
on a Windows system instead. There are several free compilers that you can download and install to make
that possible.
- At various places in my lessons, I refer to the VTC Style Guide
for C/C++ Programming.
- Although most of the material above is non-operating system specific, I do encourage my
students to explore the curses terminal handling library—something that is usually seen
as particular to Unix. I believe that curses is an interesting example of a third party
library as well as just plain fun to explore. Accordingly, I have written a short document to help students get up to speed with curses.
- I have also posted materials for a one-semester course in C++ and object-oriented
programming. The prerequisite for that course is the successful completion of this course in
C. When you are finished reading over the lessons in this course, I invite you to continue
your study with my C++ tutorial.
© Copyright 2023 by Peter Chapin.
Last Revised: August 4, 2023