Example C Programs
Here are a bunch of short example C programs.
- Programs from the textbook
- hello.c, the traditional "Hello world!"
program, copied out of the textbook.
- depth.c, the "depth" program from chapter 1,
copied out of the textbook.
- mycat.c, which does the same job as the "cat"
command, at least in a simple form: with no arguments, it copies stdin
to stdout, and with one argument, it copies the specified file to
- mycat2.c, a more general version that allows
more than one file. It's also restructured to use a "dumpfile" function
rather than doing the copying in-line.
- clongword.c, which finds the longest word
- clongword2.c, which also finds the longest
word in stdin, but it uses scanf rather than reading character by
- clongword3.c, which does the exact same
thing, but is a little more "bulletproof" in that it refuses to read a
longer word than it has space for. Demonstrates use of sprintf.
You are visitor number
to this and related
pages since Feb. 8,
Tue Oct 29 12:13:19 EST 1996
Stephen Bloch / email@example.com