C Programming Homework #10: File I/O

Due: Monday, April 18, 2016

For this assignment you will continue working with the Yibble source code. See also Lesson #24 in my C tutorial.

You will probably want to create a new branch in the repository for this assignment. Use the command:

  $ git status

to verify that you have no uncommitted changes to your branch for Homework #9. If you do, you should commit those changes to your hw09 branch. Next do the following:

  $ git checkout master
  $ git pull
  $ git branch hw10
  $ git checkout hw10

These commands first switch you back to the master branch (the version without your Homework #9 changes), gets any updates from me (the "pull"), and then creates and switches to a new branch for this assignment. Your Homework #9 material is safely stored in its own branch so while you won't see those changes in the files any more, they are still available to you.

  1. Add the following functions to text.c:

      void read_file( char *file_name );
      void write_file( char *file_name );
    

    You should add the declarations above to text.h and the implementation of the functions in the .c file. The read_file function should open the file with the given name and read its contents into the text array. It should be sure to set the other global variables in text.c appropriately.

    The write_file function should write the context of the text array to the named file. Be sure to handle the gap properly (recall that the gap is not really part of the file's data).

  2. Modify the main function so that it calls read_file on afile.txt when the program first starts and calls write_file on afile.txt when the program ends. Yibble should now be able to edit that one file, saving the changes between sessions.

Submit the file text.c to Moodle. You do not need to submit the other files you edited for this assignment.


Last Revised: 2016-04-12
© Copyright 2016 by Peter C. Chapin <PChapin@vtc.vsc.edu>