The readdir API reads the next entry within a directory. The first time you call readdir, the “next” entry is the first entry in the directory. Use readdir to sequentially read through the contents of a directory. Use the rewinddir API if you need to reposition readdir back to the first entry of the directory.
The parameter description for the readdir API is shown in Figure 14.15. This API takes just one parameter, Dirp, which is defined as a pointer to DIR. This is the pointer that was returned by the opendir API.
struct dirent *readdir (DIR *dirp)
The readdir API also returns a pointer that points at a structure of type dirent. The dirent structure is defined in the API documentation ...