This is a C program to show directory contents in a Unix machine
#include<stdio.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<string.h>
#include<dirent.h>
main()
{
struct dirent *p;
char a[50];
printf("\nEnter the directory ---------------->: \n");
scanf("%s",a);
DIR *f=opendir(a);
printf("\n---------------directory contents are ----------------- \n");
while((p=readdir(f))!=NULL)
{
printf("%s\n",p->d_name);
}
closedir(f);
}
Warning : program is written using system calls in Unix
1 comments:
i have tried it,its coool
pls include an error msg is dir is not found
spec@spec-gear:~$ ./a.out
Enter the directory ---------------->:
spec
---------------directory contents are -----------------
Segmentation fault
Post a Comment
speak out... itz your time !!!