CSCI 1120 (Low-Level Computing):
Sample Programs
Disclaimer: Code linked from this page is intended as a
cleaned-up and commented version of examples from class.
Many programs could be further improved with
regard to functionality or design, but then they would
no longer be as close to what we did in class.
Programs
- "Hello, world" program (1/31):
hello.c.
- Program to find roots of a quadratic equation (2/14):
roots.c.
- Simple program to test sort function (2/21):
sort.c.
- Simple string example (3/07):
replace-letter.c.
- Another simple string example (not in class):
string-length.c and
string-length-1.c.
- Quotient/remainder example (3/21):
quotient-remainder.c.
- Pointer example (3/21):
pointer-demo.c.
- Program to copy characters from stdin to stdout (3/28):
copy.c.
- Program to copy a file (not in class):
copy-file.c.
- Program to echo command-line arguments (3/28):
echo-arguments.c.
- Program to read numbers from a file, double them, and write
results to a file (not in class):
copy-and-double.c.
- Program to get and echo text input, line by line (not in class):
echo-lines.c.
- Slightly improved simple program to test sort function (4/11):
sort-improved-1.c.
- Program to show internal representation of int and double variables
(4/11):
show-in-hex.c.
(Also illustrates use of union.)
Alternative version using copying instead:
show-in-hex-1.c.
- Recursive version of simple string example (4/18):
string-length-2.c.
- Further modified program to test/demonstrate sort function (4/18):
sort-improved-2.c.
- Unsorted linked list and test program (4/18, 4/25):
Other files
- Sample makefile Makefile
for compiling C programs.
Note:
To obtain a makefile, use your browser's download function;
cutting and pasting will likely turn the tabs in the makefile
into spaces and cause it to not work.
Put the makefile in the directory in which you want to
compile.
All the makefiles linked from this page begin with
brief documentation on their use (the "usage examples").