3. Print the first 5 lines of a file (lastnameHEAD.c):
Write a C program that takes a file as an argument and prints its first 5 lines (equivalent to using
head -n 5). If this program does not receive the correct number of arguments, or if it fails to
open the given file, it should return errors.
Hint: Write a function readLine() that reads characters until it hits a newline character -- run
this function in a loop to get and print 5 lines. Assume that the file has at least 5 lines.
$/carberryHEAD apache.txt
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
$/carberryHEAD notfile
Error opening file
$/carberryHEAD
Usage: /carberryHEAD file
Figure 1 -- Expected behavior of lastnameHEAD