#include<dirent.h>
#include<stdio.h>
main()
{
const char buffer[50];
struct dirent **collect;
int n;
printf("\n\nEnter the directory:");
scanf("%s",&buffer);
n=scandir(buffer,&collect,0,alphasort);
if(n<0)
perror("Error");
else
{
while(n--)
{
printf("\n %s",collect[n]->d_name);
free(collect[n]);
}
free(collect);
}
printf("\n\n End");
}
OUTPUT
./a.out
Enter Directory
.
tist
f1
f2
file.c
cat.c
copy.c
No comments:
Post a Comment