what is the error in following C Program ??- to store the content of a Directory in a Data Structure
#include <stdio.h> #include <sys/types.h> #include <dirent.h> #include <conio.h> #include <alloc.h>
void main (void) {  DIR *dp; struct dirent *ep; // char *ep; struct node { char *name; struct node *next;  }; struct node *start ='\0'; struct node *temp,*temp1; clrscr(); dp = opendir ("e:\\books");
if (dp != NULL) { while (ep = readdir (dp)) { //puts (ep->d_name); //printf("%s\n",ep); //printf("\n%s",ep->d_name); if(start==NULL)  { temp = (struct node *)malloc(sizeof(struct node)); temp->name = ep->d_name;  //printf("\n%s",temp->name); // puts(temp->name); temp->next=NULL; start =temp;} else { temp1 = (struct node *)malloc(sizeof(struct node)); temp1->name=ep->d_name; //printf("\n%s",temp1->name); // puts(temp1->name); //printf("\n%s",temp->name); /*I have a problem with just above one statement, which shows the current directory name rather than previous directory name. means it shows the same Directory name for both temp->name & temp1->name */ temp1->next=NULL; temp->next=temp1; temp =temp1; } } temp=start; printf("\n\t---------  CONTENT OF THE DIRECTORY ----------\n"); while(temp->next!=NULL) { if(temp->name=="."||temp->name=="..") continue; printf("\n%s",temp->name); temp=temp->next; } printf("\n%s",temp->name); (void) closedir (dp); } else perror ("Couldn't open the directory");  getch(); } 
/*I have tried this program which output gives me the last Directory name n+2 times. if a directory has n number of Directories. Such as a folder named as "PUNEET"( E:\\Books) have 3 subfolders named as 1,2 & 3,for this output of this program is 5 times 3 like this
3
3
3
3
3 rather than
1
2
3.

I hope now problem is clear Please ! tell me where i am wrong. this program has a logical mistake.
or please provide me a program which can store the file & folders of a directory into a linked list data structure.

Thank s !
*/

what is the error in following C Program ??- to store the content of a Directory in a Data Structure
===

#include <stdio.h> #include <sys/types.h> #include <dirent.h> #include <conio.h> #include <alloc.h>
void main (void) {  DIR *dp; struct dirent *ep; // char *ep; struct node { char *name; struct node *next;  }; struct node *start ='\0'; struct node *temp,*temp1; clrscr(); dp = opendir ("e:\\books");
if (dp != NULL) { while (ep = readdir (dp)) { //puts (ep->d_name); //printf("%s\n",ep); //printf("\n%s",ep->d_name); if(start==NULL)  { temp = (struct node *)malloc(sizeof(struct node)); temp->name = ep->d_name;  //printf("\n%s",temp->name); // puts(temp->name); temp->next=NULL; start =temp;} else { temp1 = (struct node *)malloc(sizeof(struct node)); temp1->name=ep->d_name; //printf("\n%s",temp1->name); // puts(temp1->name); //printf("\n%s",temp->name); /*I have a problem with just above one statement, which shows the current directory name rather than previous directory name. means it shows the same Directory name for both temp->name & temp1->name */ temp1->next=NULL; temp->next=temp1; temp =temp1; } } temp=start; printf("\n\t---------  CONTENT OF THE DIRECTORY ----------\n"); while(temp->next!=NULL) { if(temp->name=="."||temp->name=="..") continue; printf("\n%s",temp->name); temp=temp->next; } printf("\n%s",temp->name); (void) closedir (dp); } else perror ("Couldn't open the directory");  getch(); } 
/*I have tried this program which output gives me the last Directory name n+2 times. if a directory has n number of Directories. Such as a folder named as "PUNEET"( E:\\Books) have 3 subfolders named as 1,2 & 3,for this output of this program is 5 times 3 like this
3
3
3
3
3 rather than
1
2
3.

I hope now problem is clear Please ! tell me where i am wrong. this program has a logical mistake.
or please provide me a program which can store the file & folders of a directory into a linked list data structure.

Thank s !
*/
