Example programs for/from the C programming language lecture
-
tarball of all the example programs (including README and Makefile)
-
README
-
Makefile - to build all of the example programs
-
arrays_ptrs.c - similarities of arrays and pointer
references.
-
command_args.c - accessing the command line
arguments to a C program (when run from the Unix command line).
-
count_char.c - simple character I/O and processing.
-
count_char2.c - similar to
count_char.c except that it uses a for loop instead of a while loop.
-
filecopy.c - copies from stdin to stdout.
-
filecopy2.c - similar to
filecopy.c but using a more compact notation in which I/O and
assignment are embedded in the test portion of a while loop.
-
func_ptrs.c - passing "by reference" and the use of
a pointer to a function.
-
hello.c - "hello world" variant including an
output decision based on user input as well as a basic function call.
-
hello2.h,
hello2a.c,
hello2b.c - functionality of
hello.c divided into separate modules (files) to demonstrate the use of
#include files, and separate compilation.
-
io.c - sample C I/O code provided as part of programming
assignment #1.
-
mem_mgt.c - structure definition, structure pointer
declaration, allocation/deallocation of memory, and the dangers of careless
pointer management/use. Note that this code contains examples of what NOT to
do.
-
struct_ptrs.c - the "->" shorthand for
accessing the member of a structure via pointer dereference; demonstrates
the importance of understanding operator precedence (includes a
compilation error).
-
swap.c - consequences of "pass by value" function
arguments.
-
temps.c,
temps2.c,
temps3.c,
temps4.c - some simple, iterative, arithmetic
processing and output.
(Note: Some examples derived from The C Programming Language,
Second Edition, by Brian W. Kernighan and Dennis M. Ritchie)