Skip to content

Instantly share code, notes, and snippets.

@32teeth
Created December 18, 2019 11:34
Show Gist options
  • Save 32teeth/0038c625a47c0baec3a9bf12f012e9d2 to your computer and use it in GitHub Desktop.
Save 32teeth/0038c625a47c0baec3a9bf12f012e9d2 to your computer and use it in GitHub Desktop.
```
struct dirent
```
```
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
int
main(void)
{
struct dirent **namelist;
int n;
n = scandir(".", &namelist, 0, alphasort);
if (n < 0)
perror("scandir");
else {
while (n--) {
printf("%s\n", namelist[n]->d_name);
free(namelist[n]);
}
free(namelist);
}
}
```
[scandir](https://pubs.opengroup.org/onlinepubs/9699919799/functions/scandir.html)
[rewinddir](https://pubs.opengroup.org/onlinepubs/007908799/xsh/rewinddir.html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment