• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4084
  • Last Modified:

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);
      }

0
narku_narku
Asked:
narku_narku
  • 4
  • 2
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now