CSE342 - Lab 1: UNIX and C Programming


0. Preliminaries

1. X-Windows


2. An Intro to C Programming

3. Editing C Code


4. Using emacs modes

5. make

6. Compilation within emacs

7. Command line arguments in Unix C

8. UNIX File I/O


9. File Descriptors


10. Reading and Writing


11. Accessing files

12. System calls for file I/O

13. Exercises
    For the following exercise, write the required C code and an appropriate Makefile. Before you leave, show the TA your Makefile and code for each of the exercises:

    1. Create a Makefile for the copy program above. Run make to compile without errors. Add another option to gcc to have it generate all warnings (-Wall) of possible sources of errors. Run make, and note the warnings. Modify the copy.c program to eliminate the warnings.
    2. open and creat return a value less than zero if the operation fails. Look up the library procedure perror and modify the copy program to print an appropriate error message if either the open or creat system calls fail. Also add a check to make sure that the user specified exactly two arguments.
    3. Modify the copy program to count the number of bytes and the number of lines of text copied. Each text line in Unix is delineated by the character '\n'. Use the wc command to verify the counts that your program generates on a non-trivial file.
    4. (Optional) The result of an assignment statement is left in the current expression and can be used for later evaluation:

      if ((a = b + c) == d) { ...}

      is valid C code. Use this construct to eliminate a call to read() in the copy program.

    Be sure to properly label your program listing; e.g., something like:

        /**********************/
        /* Joe Smith          */
        /* CSE342             */
        /* Lab 1              */
        /* 28 August 2007     */
        /**********************/
    
    as you will lose points for not doing so in assignments that are handed in (as well as for lack of comments, white space, modularity, etc.).

Last revised 28 August 2007, Prof. Davison.