?
Solved

Need help in resolving an error in the attached code

Posted on 2006-05-20
2
Medium Priority
?
213 Views
Last Modified: 2010-04-15
When the below code is executed, it gives an error in the statement below statement.
T=Binary_Tree(list, 0, number);

The error says.
"Non portable pointer assignment in function main". I am using TurboC on win32.




#include<stdio.h>
#include<conio.h>

/* -------------------------------------------------------  */
/* Definitions */

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*);
void in_order(struct node*);


/* -------------------------------------------------------  */
/* Function to create an 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 [mid];

if(lower>=upper)
{
      node->left_child=NULL;
      node->right_child=NULL;
      return(node);

}
if(lower<=mid-1)
      node->left_child=binary_tree(list,lower,mid-1);
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("\n");
            for(i=0;i<level;i++)
                  printf("    ");

            printf(" %c", T->info);
            output(T->left_child,level+1);
      }
}


/* ------------------------------------------------------- */
/* Pre_order Traversal */

void pre_order (struct node *node)
{
      if(node)
      {
            printf("%c", node->info);
            pre_order (node->right_child);
            pre_order(node->right_child);
      }
}


/* ------------------------------------------------------- */
/* In_order traversal */

void in_order(struct node *node)
{
      if(node)
      {
            in_order(node->left_child);
            printf("%c",node->info);
            in_order(node->right_child);
      }
}


/* ------------------------------------------------------- */
/* The entry point - Main */

void main()
{
      char list[100];
      int number = 0;
      char info;
      char choice;
      struct node *T=(struct node*)malloc(sizeof(struct node));
      T=NULL;
      printf("\n Input choice 'b' to break:");
      choice=getchar();
      fflush(stdin);
      while(choice!='b')
      {
            printf("\n Input information of the node:");
            scanf("%c", &info);
            list[number++] = info;
            fflush(stdin);
            printf("\n Input choice 'b' to break:");
            choice=getchar();
            fflush(stdin);
      }
      number--;
      printf("\n number of elements in the list is %d", number);
      T=Binary_Tree(list, 0, number);
      output(T,1);
      printf("\n pre_order traversal\n');
      pre_order(T);
      printf("\n In_order traversal \n");
      in_order(T);
0
Comment
Question by:swtirs
2 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 16726676
Binary_Tree is not the same as binary_tree
0
 

Author Comment

by:swtirs
ID: 16726685
I figured out. Yet your provided the help what wanted by me. Thank you.
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question