Lecture 16: October 30, 2019

Reading: C text, §11
Due: Homework #3, due November 8, 2019


  1. Greetings and felicitations!
  2. Arrays of strings
    1. int main(int argc, char *argv[]) (same as int main(int argc, char **argv))
    2. Example programs: echo.c, echo2.c
  3. Files
    1. Review files and file pointers — mention file descriptors as underlying mechanism
    2. Standard I/O library (stdio.h)
    3. Standard input, output, error (stdin, stdout, stderr)
    4. Opening, closing files (fopen, fclose)
  4. Reading, writing characters and lines
    1. Reading text data as lines (fgets, gets — do not use this!)
    2. Reading text data as characters (fgetc, getc, getchar, ungetc)
    3. Writing text data as lines (fputs, puts— latter adds a trailing newline)
    4. Writing text data as characters (fputc, putc, putchar)
  5. Reading, writing text data with a fixed format
    1. Reading in text data with a fixed format (fscanf, scanf)
    2. Outputting text data with a fixed format (fprintf, printf)
  6. Printing the contents of a file
    1. Simple copy (scopy.c)
    2. Using fputs (printfile1.c)
    3. Using putchar (printfile2.c)
    4. Using command-line arguments (printfile3.c)
  7. Binary file I/O
    1. Reading with fread
    2. Writing with fwrite
    3. Binary simple copy (sbcopy.c)
  8. Other useful stuff
    1. Test for end of file (feof, also EOF or NULL)

UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: [email protected]
ECS 36A, Programming and Problem Solving
Version of October 30, 2019 at 8:10PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh