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 |
Write a routine that prints out a 2-D array in spiral order
main() { int i = 100; clrscr(); printf("%d", sizeof(sizeof(i))); } a. 2 b. 100 c. 4 d. none of the above
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }
how many processes will gate created execution of -------- fork(); fork(); fork(); -------- Please Explain... Thanks in advance..!
main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }
main() { int i=0; while(+(+i--)!=0) i-=i++; printf("%d",i); }
9 Answers CSC, GoDB Tech, IBM,
1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18.
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)); } }
main() { int i=5,j=10; i=i&=j&&10; printf("%d %d",i,j); }
main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }
find A^B using Recursive function
Which version do you prefer of the following two, 1) printf(ā%sā,str); // or the more curt one 2) printf(str);