How to read a directory in a C program?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
void main() { int *mptr, *cptr; mptr = (int*)malloc(sizeof(int)); printf(ā%dā,*mptr); int *cptr = (int*)calloc(sizeof(int),1); printf(ā%dā,*cptr); }
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
what is variable length argument list?
find simple interest & compund interest
What is the hidden bug with the following statement? assert(val++ != 0);
Is it possible to type a name in command line without ant quotes?
What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;
main() { int k=1; printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE"); }
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); }
#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above
main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }
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,