• C

Declaration terminated incorrectly error during compile and also check the coding

hy experts,
I have solved the following question in 'C' language but its show the error which is "declaration terminated incorrectly" during compile. I am not able to solve this error.Please help me and also check the coding of the question.The question is follows:-

Write a program in 'C' programming language to list the nodes of a binary tree in the following way:
List the root,then nodes at depth 1,followed by nodes at depth 2,and so  on.
Your program should have linear time complexity

And the coding which is written by me, please check the coding:--

#include<stdio.h>
struct NODE
      {
            char info;
            struct NODE *left_child;
            struct Node *right_child;
      };
struct NODE binary_tree(char*,int,int);
void output (struct NODE*,int);
void pre_order(struct NODE*);
/*function to create on binary tree*/
struct NODE binary_tree(char *list,int lower,int upper);
{
      struct NODE *node;
      int mid=(lower+upper)/2;
      node=(struct NODE*) malloc (sizeof(struct NODE));
      node->info=(list[**]);
      if(lower>=upper)
      {
            node->left_child=NULL;
            node->right_child=NULL;
            return(node);
      }
      if(lower<=child-1)
            node->left_child=binary_tree(list,lower,mid);
       else
            node->left_child=NULL;
            if(mid+1 <=upper)
                  node->right_child=binary_tree(list,mid+1,upper);
       else
       node->right_child=NULL;
      return(node);
      }
      /*output function*/
      void output(struct NODE *t,int level)
      {
      int i;
      if(t)
      {
            output(t->right_child,level+1);
            printf("In");
            for(i=0;i<level;i++)
                  printf(" ");
                  printf("%c",t->info);
                  output(t->left_child,level+1);
      }
      /*preorder traversal*/
      void preorder(struct NODE *NODE)
      {
            if(NODE)
            {
                  printf("%c",node->info);
                  preorder(node->left_child);
                  preorder(node->left_child);
            }
      }
      /*function main*/
      {
      char list[100];
      int number=0;
      char info;
      char choice;
      struef NODE *t=(struef node*)malloc(size of (struef NODE));
      t=NULL;
      printf("In Input choice 'b' to break:");
      choice=get char();
      ffclush (stdin);
      while(choice!='b')
      printf("In Input information of the node:");
      scanf("%c"<&info);
      list[number++]=info;
      ffclush(stdin);
      printf("In Input choice 'b' to break:");
      choice=getchar();
      ffclush(stdin);
      }
      number;
      printf("In number of elements in the list is %d",number);
      t=binary_tree(list,0,number);
      output(t,1);
      printf("in preorder travrsal in ");
      preorder(t,1);
      }

narku_narkuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sys_ProgCommented:


Your syntax errors============

#include<stdio.h>
struct NODE
     {
          char info;
          struct NODE *left_child;
          struct Node *right_child;================== Node should be NODE
     };
struct NODE binary_tree(char*,int,int);
void output (struct NODE*,int);
void pre_order(struct NODE*);
/*function to create on binary tree*/
struct NODE binary_tree(char *list,int lower,int upper);============== semicolon not needed
{
     struct NODE *node;
     int mid=(lower+upper)/2;
     node=(struct NODE*) malloc (sizeof(struct NODE));
     node->info=(list[**]);==============================what is [**]....??
     if(lower>=upper)
     {
          node->left_child=NULL;
          node->right_child=NULL;
          return(node);============================= Your return type is a Node type but u are retuning a pointer to Node=================
     }
     if(lower<=child-1)============================child node not declared
          node->left_child=binary_tree(list,lower,mid);============= Again return type of this function should be Pointer to Node
      else
          node->left_child=NULL;
          if(mid+1 <=upper)
               node->right_child=binary_tree(list,mid+1,upper);============= Again return type of this function should be Pointer to Node
      else
      node->right_child=NULL;
     return(node);============================= Your return type is a Node type but u are retuning a pointer to Node=================

     }
     /*output function*/
     void output(struct NODE *t,int level)
     {
     int i;
     if(t)
     {
          output(t->right_child,level+1);
          printf("In");
          for(i=0;i<level;i++)
               printf(" ");
               printf("%c",t->info);
               output(t->left_child,level+1);
     }
     /*preorder traversal*/
     void preorder(struct NODE *NODE) =========== variable NODE shoudl be node
thus declaration shoudl be      void preorder(struct NODE *node)
     {
          if(NODE)=================== NODE should be node
          {
               printf("%c",node->info);
               preorder(node->left_child);
               preorder(node->left_child);
          }
     }
     /*function main*/
     {
     char list[100];
     int number=0;
     char info;
     char choice;
     struef NODE *t=(struef node*)malloc(size of (struef NODE));========== struct mispelled, sizeof shoudl be one word=================
     t=NULL;
     printf("In Input choice 'b' to break:");
     choice=get char();=============use getche() OR getch() instead
     ffclush (stdin);
     while(choice!='b')
     printf("In Input information of the node:");
     scanf("%c"<&info);==============< should be ,
     list[number++]=info;
     ffclush(stdin);
     printf("In Input choice 'b' to break:");
     choice=getchar();
     ffclush(stdin);
     }=========================This should be at the end your main gets closed here
     number;==============what is this=========
     printf("In number of elements in the list is %d",number);
     t=binary_tree(list,0,number);
     output(t,1);
     printf("in preorder travrsal in ");
     preorder(t,1);=================parameters incorrect
     }
0
Sys_ProgCommented:
REctify the above errors and have a look at your logic, if not getting, let us know

Also As per your requirement, a preorder traversal won;t do, because u have to print the nodes at one level before going to the next level.

But preorder won;'t do this
0
narku_narkuAuthor Commented:
hello sys_prog
thanks for help please give me right coding for this question in the complete manner. i am not able to understand the error that u have detect . futher thanks for help
0
Become a Leader in Data Analytics

Gain the power to turn raw data into better business decisions and outcomes in your industry. Transform your career future by earning your MS in Data Analytics. WGU’s MSDA program curriculum features IT certifications from Oracle and SAS.  

Sys_ProgCommented:
HEy narku_narku

HEre's your snytax error free code

I have not seen at the logic, I think U should have a look at it and then if u face any problem we can help u

U should first Try it yourself


#include<stdio.h>
struct NODE
     {
          char info;
          struct NODE *left_child;
          struct NODE *right_child;
     };
struct NODE * binary_tree(char*,int,int);
void output (struct NODE*,int);
void pre_order(struct NODE*);
/*function to create on binary tree*/
struct NODE * binary_tree(char *list,int lower,int upper)
{
     struct NODE *node ;
     int child ;
     int mid=(lower+upper)/2;
     node=(struct NODE*) malloc (sizeof(struct NODE));
     node->info=(list[0]);
     if(lower>=upper)
     {
          node->left_child=NULL;
          node->right_child=NULL;
          //return(node);
     }
     if(lower<=child-1)
          node->left_child=binary_tree(list,lower,mid);
      else
          node->left_child=NULL;
          if(mid+1 <=upper)
              node->right_child = binary_tree(list,mid+1,upper);
      else
      node->right_child=NULL;
     return(node);
}

/*output function*/
void output(struct NODE *t,int level) {
 
     int i;
     if(t)
       {
          output(t->right_child,level+1);
          printf("In");
          for(i=0;i<level;i++)
               printf(" ");
               printf("%c",t->info);
               output(t->left_child,level+1);
       }
}      

     /*preorder traversal*/
     void preorder(struct NODE *node)
     {
          if(node)
          {
               printf("%c",node->info);
               preorder(node->left_child);
               preorder(node->left_child);
          }
     }


     /*function main*/
     int main ( void )
     {
     char list[100];
     int number=0;
     char info;
     char choice;
     struct NODE *t=(struct NODE*)malloc(sizeof (struct NODE));
     t=NULL;
     printf("In Input choice 'b' to break:");
     choice=getch();
     fflush (stdin);
     while(choice!='b')
     printf("In Input information of the node:");
     scanf("%c",&info);
     list[number++]=info;
     fflush(stdin);
     printf("In Input choice 'b' to break:");
     choice=getchar();
     fflush(stdin);
     
     
     printf("In number of elements in the list is %d",number);
     t=binary_tree(list,0,number);
     output(t,1);
     printf("in preorder travrsal in ");
     //preorder(t,1);
     }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AllRounderCommented:
Hi narku_narku and Sys_Prog

I just came across this code...
I could not get the Significance  of the integer variable 'child'.
If  narku_narku or Sys_Prog can throw some light, it would be helpful.
If narku_narku can explain what he wants as output, may be we can rewrite the code in a simpler way.

Regards,
AR
0
Sys_ProgCommented:
Hi AllRounder,

Actually I do not want to give the complete code. I think the questioner should build his logic of doing it and we can correct him if he is gone wrong somewhere

Actually his code does contain a lot of pitfalls which he need to discover

0
narku_narkuAuthor Commented:
hy allrounder,
as u say what i want the output. the question is follows as :

Write a program in 'C' programming language to list the nodes of a binary tree in the following way:
List the root,then nodes at depth 1,followed by nodes at depth 2,and so  on.
Your program should have linear time complexity.

as u say me u give me the complete code. please see the question and give me complete code in a simple way. futher thanks for help.


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.