CSC 161 Schedule Readings Labs & Projects Homework Deadlines Resources

Advanced File Input and Output

Summary: This lab reinforces formatted input using files and introduces and binary file I/O.

Formatted I/O

  1. Download and compile, state-year.c. (Note: Do not download the data file yet.)
    1. Run the program. Try to generate at least three different kinds of error messages.
    2. Download the accompanying data file state-income.txt. Run the program for a few valid years and ensure you understand how it works.
  2. Using state-year.c as a template, write a program state-year-decrease.c which prints for each state, each pair of years for which the median income decreased. For example,
    ./state-year-decrease
    United States        
    Alabama               1992-1993
    Alaska                1996-1997 1991-1992 1990-1991 1985-1986 1984-1985 1981-1982
    Arizona               1992-1993 1982-1983
    Arkansas              1995-1996 1992-1993
    California            1992-1993
    Colorado             
    Connecticut          
    Delaware              1994-1995 1992-1993
    ...
    Be sure you cite the origins of your derivative work and clarify which portions are original to your new program and authored by you.

Binary I/O

Image I/O

  1. Write a program that instructs the robot to take a picture and then writes the struct with the picture data to a file using fwrite.
  2. Write a program that uses fread to read the binary data for a picture struct and the uses rDisplayPicture from the MyroC header to display the picture.

General Data I/O

  1. Write a program called intwrite.c that reads in a series of integers from standard input using any method you prefer. The program should then imediately write these integers to a binary file of your choosing using fwrite.
  2. Write a companion program called intread.c that reads in integers from the binary file and writes them each on a new line to stdout.