Last active
April 24, 2025 21:16
-
-
Save evaporei/73dc4fa0f2823ce96783f3858a9f135d to your computer and use it in GitHub Desktop.
scandir example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dirent.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
int main(void) { | |
struct dirent **namelist; | |
int n = scandir(".", &namelist, NULL, alphasort); | |
if (n < 0) { | |
perror("scandir"); | |
} else { | |
for (int i = 0; i < n; i++) { | |
printf("%s\n", namelist[i]->d_name); | |
free(namelist[i]); | |
} | |
free(namelist); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment