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

void main() { int *mptr, *cptr; mptr = (int*)malloc(sizeof(int)); printf(ā€œ%dā€,*mptr); int *cptr = (int*)calloc(sizeof(int),1); printf(ā€œ%dā€,*cptr); }

1 Answers  


main() { int i, j; scanf("%d %d"+scanf("%d %d", &i, &j)); printf("%d %d", i, j); } a. Runtime error. b. 0, 0 c. Compile error d. the first two values entered by the user

2 Answers   HCL,


what is variable length argument list?

2 Answers  


find simple interest & compund interest

2 Answers  


What is the hidden bug with the following statement? assert(val++ != 0);

1 Answers  






Is it possible to type a name in command line without ant quotes?

1 Answers   Excel, Infosys,


What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;

1 Answers  


main() { int k=1; printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE"); }

1 Answers  


main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }

1 Answers  


#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above

3 Answers   HCL,


main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }

1 Answers  


main() { signed int bit=512, mBit; { mBit = ~bit; bit = bit & ~bit ; printf("%d %d", bit, mBit); } } a. 0, 0 b. 0, 513 c. 512, 0 d. 0, -513

3 Answers   HCL, Logical Computers,


Categories