---im having difficult to fix the error alots of them---
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<dir.h>
#include<dos.h>
struct node
{
char *name;
int attrib;
struct node *next;
};
int main()
{
struct node *head,*head1;
struct node *list,*list1;
struct node * place(struct ffblk ff,struct node *first,int don);
void display(struct node *first);
void print(struct node *list,int *i);
int i,c,c1,done,done1;
struct ffblk, ff,f1;
head=NULL;
head1=NULL;
done=findfirst("*.*",&ff,FA_DIREC|FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH);
done1=findfirst("*.*",&f1,FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH);
head=place(f,head,done);
display(head);
printf("*************************************************");
getch();
head1=place(f1,head1,done1);
display(head1);
printf("*************************************************");
getch();
i=0;
c1=0;
list=head;
while(list!=NULL)
{
list1=head1;
if(list1==NULL)
print(list,&i);
else
{
while(list1!=NULL)
{
if(strcmp(list->name,list1->name)==0)
c1=1;
list1=list1->next;
}
if(c1==0)
print(list,&i);
}
c1=0;
list=list->next;
}
printf(" FOLDERS = %d",i);
printf("*************************************************");
printf(" Where,");
printf(" H - Hidden");
printf(" D - Directory");
printf(" R - Read only");
printf(" S - System");
printf(" A - Archive");
getch();
free(list1);
free(list);
free(head);
free(head1);
}
void print(struct node *list,int *i)
{
void property(struct node *list);
if((strcmp(list->name,"."))!=0 && (strcmp(list->name,".."))!=0)
{
*i=*i+1;
property(list);
printf(" %s",list->name);
}
}
void property(struct node *list)
{
if(list->attrib & FA_HIDDEN)
printf("(H)");
if(list->attrib & FA_DIREC)
printf("(D)");
if(list->attrib & FA_RDONLY)
printf("(R)");
if(list->attrib & FA_SYSTEM)
printf("(S)");
if(list->attrib & FA_ARCH)
printf("(A)");
}
struct node * place(struct ffblk ff,struct node *first,int don)
{
static int j;
void create(struct node *first,char *ch,int d);
void insert(struct node *first,char *ch,int d);
int i=0,c=0;
char *p;
if(don!=0)
first=NULL;
else
{
while(don==0)
{
if(i==0)
{
first=(struct node *)malloc(sizeof(struct node));
if ((p = (char *) malloc(14)) == NULL)
exit(1);
strcpy(p,ff.ff_name);
create(first,p,ff.ff_attrib);
i=1;
}
else
{
if ((p = (char *) malloc(14)) == NULL)
exit(1);
strcpy(p,ff.ff_name);
insert(first,p,ff.ff_attrib);
}
don=findnext(&ff);
c=c+1;
}
}
if(j==0)
{
printf("*************************************************");
printf(" %d FILES & FOLDERS",c);
j+=1;
}
else
printf(" %d FILES",c);
return(first);
}
void create(struct node *first,char *ch,int d)
{
char *p;
if ((p = (char *) malloc(sizeof(ch))) == NULL)
exit(1);
p=ch;
first->name=p;
first->attrib=d;
first->next=NULL;
return;
}
void insert(struct node *first,char *ch,int d)
{
struct node *temp,*list;
char *p;
list=first;
while(list->next!=NULL)
list=list->next;
if ((p = (char *)malloc(sizeof(ch))) == NULL)
exit(1);
p=ch;
temp=(struct node *)malloc(sizeof(struct node));
temp->name=p;
temp->attrib=d;
temp->next=NULL;
list->next=temp;
return;
}
void display(struct node *first)
{
struct node *list;
void property(struct node *list);
list=first;
if(list==NULL)
printf("NULL");
else
{
while(list->next!=NULL)
{
property(list);
printf("%s %d",list->name,list->attrib);
list=list->next;
}
property(list);
printf("%s %d",list->name,list->attrib);
}
return;
}