How to read a directory in a C program?

Answers were Sorted based on User's Feedback



How to read a directory in a C program? ..

Answer / lakshmi sreekanth

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>

main()
{
struct dirent *dp;
DIR *dfd = opendir("/home/sreekanth");

if(dfd != NULL)
{
while((dp = readdir(dfd)) != NULL)
printf("%s\n", dp->d_name);
closedir(dfd);
}
return 0;
}

Is This Answer Correct ?    14 Yes 4 No

How to read a directory in a C program? ..

Answer / muthu

please write the correct program with output...

by prof.muthu m.c.a phd etc..
ph:9962940220

Is This Answer Correct ?    6 Yes 4 No

How to read a directory in a C program? ..

Answer / rakesh

void main()
{
char path[100];
cout<<"Enter the path of directory::";
cin.getline(path,100);
system("cd path");
system("dir");
} // In windows
// For linux change dir to ls.

Is This Answer Correct ?    10 Yes 15 No

How to read a directory in a C program? ..

Answer / prince

main()
{
char path[100];
printf("Enter the path of directory:");
scanf("%s",path);
system("cd path");
system("ls");
}

Is This Answer Correct ?    2 Yes 20 No

Post New Answer

More C Code Interview Questions

Give a oneline C expression to test whether a number is a power of 2?

25 Answers   EA Electronic Arts, Google, Motorola,


How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices specified. 2. with only the co-ordinates of the top vertex given.

1 Answers  


WAP to display 1,2,3,4,5........N

2 Answers  


main() { int i=10; void pascal f(int,int,int); f(i++,i++,i++); printf(" %d",i); } void pascal f(integer :i,integer:j,integer :k) { write(i,j,k); }

1 Answers  


Finding a number multiplication of 8 with out using arithmetic operator

8 Answers   Eyeball, NetApp,






What is your nationality?

1 Answers   GoDB Tech,


#define int char main() { int i=65; printf("sizeof(i)=%d",sizeof(i)); }

1 Answers  


main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }

1 Answers   DCE,


What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql

0 Answers  


What are the files which are automatically opened when a C file is executed?

1 Answers  


main() { static int a[3][3]={1,2,3,4,5,6,7,8,9}; int i,j; static *p[]={a,a+1,a+2}; for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i)); } }

1 Answers  


Is it possible to print a name without using commas, double quotes,semi-colons?

7 Answers  


Categories