Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
---im having difficult to fix the error alots of them---

C++
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#include<dir.h>
#include<dos.h>

struct node
{
 char *name;   /* used to get file / folder name. */
 int attrib;   /* used to get it's attribute.  */
 struct node *next;  /* concept of Linked list */
};
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;
 //clrscr();
 done=findfirst("*.*",&ff,FA_DIREC|FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH);
 /* struct variable "f" contains all files and folders information */
 done1=findfirst("*.*",&f1,FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH);
 /* struct variable "f1" contains all files information */
 head=place(f,head,done);  /* content of f is placed in struct head */
 display(head);
 /*
  Note : f contains name of files and folders with their attributes
  in f.ff_name, f.ff_attrib which is assigned to name, attrib in
  the struct node
 */
 printf("*************************************************");
 getch();
 head1=place(f1,head1,done1); /* content of f1 is placed in struct head1
*/
 display(head1);
 /*
  Note : f1 contains name of files and folders with their attributes
  in f1.ff_name, f1.ff_attrib which is assigned to name, attrib in
  the struct node
 */
 printf("*************************************************");
 getch();
 i=0;
 c1=0;
 /*
  Here, head and head1 are compared so that we could extract only
  the folders.
 */
 list=head;   /* head is assigned to list */
 while(list!=NULL)
 {
   list1=head1;  /* head1 is assigned to list1 */
   if(list1==NULL)   /* if there are 0 files */
    print(list,&i);   /* then display content of list */
   else
   {
    while(list1!=NULL)
    {
    if(strcmp(list-&gt;name,list1-&gt;name)==0)  /* compare list and list1 */
     c1=1;
    list1=list1-&gt;next;
    }
    if(c1==0)      /* if folder found both in list and list1*/
     print(list,&i);  /* then display content of list */
   }
   c1=0;
   list=list-&gt;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);
 /* to display folders other than default folders (. and ..)  */
 if((strcmp(list-&gt;name,"."))!=0 && (strcmp(list-&gt;name,".."))!=0)
 {
  *i=*i+1;     /* counts number of folders */
  property(list);
  printf(" %s",list-&gt;name);
 }
}

void property(struct node *list)
{    /* finds their attribute */
  if(list-&gt;attrib & FA_HIDDEN)
   printf("(H)");
  if(list-&gt;attrib & FA_DIREC)
   printf("(D)");
  if(list-&gt;attrib & FA_RDONLY)
   printf("(R)");
  if(list-&gt;attrib & FA_SYSTEM)
   printf("(S)");
  if(list-&gt;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-&gt;name=p;
 first-&gt;attrib=d;
 first-&gt;next=NULL;
 return;
}

void insert(struct node *first,char *ch,int d)
{
 struct node *temp,*list;
 char *p;
 list=first;
 while(list-&gt;next!=NULL)
  list=list-&gt;next;
 if ((p = (char *)malloc(sizeof(ch))) == NULL)
  exit(1);
 p=ch;
 temp=(struct node *)malloc(sizeof(struct node));
 temp-&gt;name=p;
 temp-&gt;attrib=d;
 temp-&gt;next=NULL;
 list-&gt;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-&gt;next!=NULL)
 {
  property(list);
  printf("%s %d",list-&gt;name,list-&gt;attrib);
  list=list-&gt;next;
 }
  property(list);
  printf("%s %d",list-&gt;name,list-&gt;attrib);
 }
 return;
}
Posted
Updated 10-Jan-12 8:08am
v3
Comments
Albert Holguin 10-Jan-12 13:52pm    
what's your error/question? I just see a code dump...
Sergey Alexandrovich Kryukov 10-Jan-12 14:01pm    
Please see the advice in the answer by Richard MacCutchan. It is deleted, but you still can read it. This is exactly what you want!
--SA
reikuxian 10-Jan-12 14:03pm    
i encode feature by feature then after i combine all the code..lots of error are shown which im confused and having trouble to solve it..
Albert Holguin 10-Jan-12 15:10pm    
I hope you don't seriously expect us to look at all that code and tell you all the things that are wrong. If you need help on a long list of errors, tackle one at a time, otherwise you'll probably get little help here.
OriginalGriff 10-Jan-12 14:08pm    
General rules to improve the quality and usefulness of answers to your questions:
1) Do not use a subject like "please help me" - we already know you need help, or you wouldn't be asking a question. Make teh subject a brief summary of you problem - ten words or so. Just enough to let us know at a glance if we know anything about the area you are having problems in.
2) Don't post your entire program - that is called a code dump, and is considered rude as we have to wade through it to find the problem area. Stick to relevant code fragments, each in their own code block, so we can see what is going on quickly.
3) Be specific about your problem. If you have a compiler error, tell us what line, and what error message. If you are getting an exception, same thing - where, and what. If your code is not doing what you think it should, then tell us what it should be doing, and what it is doing - and tell us how you make it do it.
4) Bear in mind that we can only see what you post - we can't read your mind, we can't read your screen. Very few of us can read your HDD, and generally that means taking off our tin-foil hats and letting The Voices back in so we don't do it often.

Basically, the more you help us to help you, the better our responses can be.

1 solution

It is not C++! If it was, you would create a node class and put all methods there. This is not even reasonable C. You are trying to do too much in main. Keep the body of this function to just one line like "TreeTest().Run()".

Ah, I see what's going on. You are trying to put function declarations like "void display(struct node *first); inside function… I don't know what to advise… but certainly not working at this problem anymore. Set it out and start from the very beginning, read some C++ or C manual. Learn elementary things first, do simple, very simple exercises. You are not ready to code your problem yet. And hey, millions overcame those problems; you can do it, too, only change your approach and don't rush it.

And I agree with Richard MacCutchan and would advise you to stop asking further questions at CodeProject for now. Your questions don't help you. First, get some confidence in the very basics.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900