OS Lab 1 - Warmup to C, Fall 2009
http://grace.evergreen.edu/sos
Read the introductory C programming handout, find your favorite C programming
references, and write the following C programs for warmup. Hand in a source
listing for the last program on this list (construction of the argv array
from stdin) along with a description of how your program works and what
test cases you used to validate your program.
See the Just Enough C section of the textbook web site for some C tutorials.
See also the Linus Torvald's Linux Kernel Coding Style Guide.
- Write a C program to echo command line arguments passed to your
program in the standard argv character array.
- Write a C program to read and echo lines typed at the keyboard
(stdin) until an EOF (^d) is typed at the keyboard in the first column. Use
fgets. See man fgets. Notice in the man page the #include that you must
put at the beginning of your program when you use fgets.
- Write a C program to read a line on stdin and then copy it into
another character array buffer removing whitespace as you copy. Print out both
buffers. See man isspace. Maybe you want to look at man string too.
- Write a C program to read a line on stdin and then copy just the
first word on the line (skipping leading white spaces) into another character
array buffer. Print out both buffers.
- Scan all words on a single input line from stdin and print them
out on separate lines. Use whitespace as a delimiter (eg: nl, tab, sp).
- Finally, scan all words on a single input line from stdin, store
them in a string array called argv and then echo the argv string
array.
- If you have not used dynamic memory allocation, then modify your
program to dynamically allocate all or part of your space for the
argv array using malloc or calloc. You'll need to get used to dynamic memory
allocation and management. See man malloc. Sort the words in the array
if you're feeling energetic.