Sample C Programs
Here are some sample C programs.
- 2cat.c: print a file twice
- chct1.c: count whitespace, chars, etc., version 2
- chct2.c: count whitespace, chars, etc., version 2
- copy.c: copy a string
- fact.c: compute n factorial
- fstat.c: get information about file
- ftoc1.c: Fahrenheit to Celsius version 1
- ftoc2.c: Fahrenheit to Celsius version 2
- gdb1.c: program #1 in gdb example
- gdb2.c: program #2 in gdb example
- gdb3.c: program #3 in gdb example
- hello.c: "hello, world!"
- ioc1.c: copy stdin to stdout, version 1
- ioc2.c: copy stdin to stdout, version 2
- llist.c: builds linked list
- num.c: number lines of files
- pow.c: compute exponents
- prenv.c: print environment variable values
- prs.c: generate pseudorandom saying
- prs2.c: generate pseudorandom saying (cleans up files too)
- ptrconf.c: pointer confusion
- quicksort.c: recursive quicksort
- rd1.c: read lines, print lines and char counts
- rd2.c: same as rd1.c but with pointers
- scope.c: demonstrate scope rules of C
- subr.c: show parameter passing techniques
- user.c: print user, group information
- wc1.c: count words, spaces, etc. in stdin
- wc2.c: count words, spaces, etc. in files
Send email to
[email protected].
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562
Page last modified on 11/3/97