I am accepting the path through command line input.
When I do
dir=opendir(args[1]);
it doesn\' t enter the loop...i.e dir==nu
Here is a simple way to implement ls command using c. To run use for example ./xls /tmp
#include
#include
void main(int argc,char *argv[])
{
DIR *dir;
struct dirent *dent;
dir = opendir(argv[1]);
if(dir!=NULL)
{
while((dent=readdir(dir))!=NULL)
{
if((strcmp(dent->d_name,".")==0 || strcmp(dent->d_name,"..")==0 || (*dent->d_name) == '.' ))
{
}
else
{
printf(dent->d_name);
printf("\n");
}
}
}
close(dir);
}