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

write a program in c to merge two array

2 Answers  


struct aaa{ struct aaa *prev; int i; struct aaa *next; }; main() { struct aaa abc,def,ghi,jkl; int x=100; abc.i=0;abc.prev=&jkl; abc.next=&def; def.i=1;def.prev=&abc;def.next=&ghi; ghi.i=2;ghi.prev=&def; ghi.next=&jkl; jkl.i=3;jkl.prev=&ghi;jkl.next=&abc; x=abc.next->next->prev->next->i; printf("%d",x); }

1 Answers  


const int perplexed = 2; #define perplexed 3 main() { #ifdef perplexed #undef perplexed #define perplexed 4 #endif printf("%d",perplexed); } a. 0 b. 2 c. 4 d. none of the above

1 Answers   emc2, HCL,


what is the output of the below program & why ? #include<stdio.h> void main() { int a=10,b=20,c=30; printf("%d",scanf("%d%d%d",&a,&b,&c)); }

6 Answers   CSC, IIIT,


main() { int i = 100; clrscr(); printf("%d", sizeof(sizeof(i))); } a. 2 b. 100 c. 4 d. none of the above

5 Answers   HCL,


why java is platform independent?

13 Answers   Wipro,


How to count a sum, when the numbers are read from stdin and stored into a structure?

1 Answers  


How we print the table of 2 using for loop in c programing?

14 Answers   HCL, Wipro,


find A^B using Recursive function

2 Answers  


Display the time of the system and display the right time of the other country

1 Answers  


Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

1 Answers  


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

2 Answers  


Categories