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 (most characters) entered.
Download the file
longest.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.
>
./longest
this is a long line
this is a long line
this is a longer line
this is a longer line
(CTRL-D)
Modify longest.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.
>
./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.