C Activity
Longest Line With Unit Tests

Overview

This C programming exercise will introduce you to character arrays and the use of functions. The program will accept a series of lines from stdin and keep track of the longest line that was entered (the most characters in one line).

The provided source code has four unit tests that must pass for you to receive full credit. However, passing these tests does not guarantee full credit.


Activity Part 1

Download the file longest_with_tests.c to a directory named LongestLine. Complete the readline() function and verify that you can correctly echo each line as it is entered. An EOF (CTRL-D) terminates the program. You may assume that no input line is over 80 characters long.

> gcc -g -o longest longest_with_tests.c
> ./longest
this is a long line
this is a long line
this is a longer line
this is a longer line
(CTRL-D)

  1. Create an ActivityJournal.txt and estimate the time you will need to complete the program.
  2. Keep track of the number of times you attempt to compile your program and generate a compiler error of any type. Note that number in the Activity_Journal along with the actual time to complete the program. 

Submission Part 1

Submit your source file longest_with_tests.c with Part 1 of your ActivityJournal.txt in a top level directory named LongestLine to your Git pushbox.

Activity Part 2

Modify longest_with_tests.c to  keep track of the longest line entered. Only print the longest line entered after input is complete. You will need to implement the copy() function to save the longest line.

As soon as you think you have the copy function implemented compile your program as shown and run the unit tests. Check the results carefully. All four tests must pass. When all four pass then complete the rest of this part of the activity.

> gcc -g -o test longest_with_tests.c
> ./test

> gcc -g -o longest longest_with_tests.c
> ./longest
This is a long line.
This is a longer line.
This is line has supercalifragilisticexpialidocious.
This is short.
(CTRL-D)
This is line has supercalifragilisticexpialidocious.

  1. Update Activity_Journal.txt and estimate the time you will need to complete the program.
  2. Keep track of the number of times you attempt to compile your program and generate a compiler error of any type. Note that number in the activity journal, along with the actual time to complete the program. 
  3. Place your  updated files - longest_with_tests.c  and Activity_Journal - in directory LongestLine to your Git pushbox.

Submission Part 2

Submit your source file longest_with_tests.c with a fully completed ActivityJournal.txt in a top level directory named LongestLine to your Git pushbox.

Grading Criteria

To receive full credit for this activity you do the following:

  1. Submit your work in a correctly named directory. This must be one of the top level directories in your repository.
  2. Use the exact filenames for both files: longest_with_tests.c and ActivityJournal.txt.
  3. The program must compile without any warnings.
  4. Complete Part 1 before starting Part 2.
  5. The program must compile exactly as shown in the activity.
    • You cannot use any other options.
    • Do not use the -std=c99 option.
  6. All unit tests must pass.
  7. Use good software style. Refer to the C Coding Standards document.
  8. Complete the Activity Journal for each Part including the time estimate, plan, actual time, and observations.