CS360 Midterm Exam: October 8, 2003. Question 3

Write a C program that is the equivalent of the following Unix command:
UNIX> find . -name '*.txt' -exec head -1 {} \; | sort
In other words, it finds all files reachable from the current directory whose names end with ".txt", and sorts all of their first lines lexicographically (in other words, using strcmp()). (Assume all the relevant include files are automatically included).

To help give you a clue, here's an example scenario:

UNIX> ls
d      f1.txt f2.txt f3.txt
UNIX> cat f1.txt
Hi
There
UNIX> cat f2.txt
Go Vols
UNIX> cat f3.txt
Juice Em
Big Dog!
Juice Em
UNIX> ls d
f1.txt f2.txt
UNIX> cat d/f1.txt
Hedonize 
Defeat
UNIX> cat d/f2.txt
Vinny Testaverde
is a distinct disappoinment!!
UNIX> find . -name '*.txt' -exec head -1 {} \; | sort
Go Vols
Hedonize 
Hi
Juice Em
Vinny Testaverde
UNIX>