I have a C code snippet: I have used dirent.h and used opendir and readdir to read the files I am doing a ls command duplicate using c code , for that the file should be is ascending order and case sensitivity also to be included.
#include <stdio.h>
#include <dirent.h>
int main(void)
{
DIR *d;
struct dirent *dir;
d = opendir(".");
printf("d: %d \n",d);
if (d)
{
while ((dir = readdir(d)) != NULL)
{
printf("\n %s \n", dir->d_name);
}
closedir(d);
}
else
{
printf("soory");
}
return (0);
}
I got result as
krishna-R
stat.c
temp
Bing
TempFolder
button
What i want is
Bing
button
krishna-R
stat.c
TempFolder
temp