The facilities described in this section let you read the contents of a
directory file. This is useful if you want your program to list all the
files in a directory, perhaps as part of a menu.
The opendir function opens a directory stream whose
elements are directory entries. You use the readdir function on
the directory stream to retrieve these entries, represented as
struct dirent objects. The name of the file for each entry is
stored in the d_name member of this structure. There are obvious
parallels here to the stream facilities for ordinary files, described in
I/O on Streams.