In Class Week11

  1. In emacs or vi, create a simple test.txt file that you will use to test your programs. Just add a few lines containing some words on each line.
         hello 
         goodbye
         see ya
         

  2. Write a program, echolines.c, that prompts the user to enter a file name, reads in the file name, opens the file and reads in each character echo'ing it to stdout (printing it to the terminal).
         please enter a file name> test.txt
    
         hello
         goodbye
         see ya
         

  3. Make a copy of your echolines.c program to countlines.c. Add a function, CountLines, that counts the number of lines in the given input file and returns the count to the caller. You should make a call to your CountLines program after echoing out its contents (think about the current file position).
         please enter a file name> test.txt
    
         hello
         goodbye
         see ya
    
         number of lines: 3
         
    To check that your program works you can compare its output to the wc command.
         % wc test.txt
          3                 4                    21       test.txt
          ^		        ^                    ^ 
          number of lines   number of words      number of bytes (chars)
         
    Note: the wc command counts the number of '\n's in the file as the number of lines. When you create a text file in vi, vi automatically adds a '\n' before the EOF. When you create a text file in emacs, emacs does not automatically add a '\n' before EOF. As a result, if the text.txt file above is created in emacs, wc will return 2 as number of lines, if created in vi, it will return 3. Your program should return 3 for the line count for text.txt no matter if the file has the '\n' before EOF or not (no matter if it was created by vi or emacs).

  4. modify your countlines.c program, modify your CountLines function to "return" the number of characters in the file, and print out the result in main.