Can Any one help me to resolve the error in this binary search tree program

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

 struct nodetype
 {
     int info ;
     struct nodetype *left , *right ;
 };
typedef struct nodetype *nodeptr;
nodeptr  maketree (int);
nodeptr getnode();
void setleft( nodeptr , int);
void setright(nodeptr , int);
void pretrav (nodeptr);
int main()

{
    nodeptr ptree ,p , q ;
    int number,c ;
    char ch;
    do{
        printf (" \n\t---Enter the Number ->");
        scanf("%d",&number);
        ptree = maketree(number);
        printf("\n\t---waiting for while");


        //printf ("\n\t---Entered into While loop 1");
            p=ptree;
            q=NULL;
            while (number != p->info && q !=NULL)
              {
               printf ("---\n\tEntered into While loop 2");
               p=q;
               if (number < p->info)
               q=p->left;
               else
               q=p->right;
               } /*end of w hile */
               if ( number == p->info)
                     printf ("\n\t---%d is a Duplicate number \n", number);
                else if (number < p->info)
                {

                  printf("setting left!");
                  setleft(p , number);}
                else
                  {
                      printf("setting right!");
                      setright(p , number);
                  }
               printf("Want to continue YEs Or No");
               scanf ("%c", &ch);
           } while (ch=='y');
           /*end of while */
    printf("\n\n Enter your choice \n\n 1-> Enter 1 for Pretraversal \n\n 2-> Enter 2 for Intraversal \n\n 3-> Enter 3 for post ordertraversal");
    scanf("%d",&c);
    switch(c)
    {
        case (1) :
                pretrav ( ptree);
    }


    return (0);
}/*end of main */

 nodeptr maketree (int x)

{
    printf (" \n\t---Maketree() Function is called");
    nodeptr  p ;
    p = getnode ();
    p->info = x;
    p->right = NULL;
    p->left = NULL;
    return (p);
}

 nodeptr getnode()
 {
     printf("\n\t---Getnode() function has been called");
     nodeptr  p ;
     p=(struct nodeptr *)malloc(sizeof(nodeptr));
     return p ;
 }

 void setleft(nodeptr p , int x)
  {
      nodeptr f;
      if (p == NULL)
        printf ("\n\t---void insertion\n");
      else if (p->left != NULL)
        printf("\n\t---invalid insertion\n");
      else
        f = maketree(x);
        p->left = f;
  }

  void setright( nodeptr p , int x)
  {
      if (p==NULL)
        printf ("\n\t---void insertion\n");
      else if (p->right != NULL)
        printf("\n\t---invalid insertion\n");
      else
        p->right = maketree(x);
  }

               void pretrav(nodeptr ptree)
                 {
                    if ( ptree!=NULL )
                    {
                        printf("%d\n", ptree->info);
                        preetrav(ptree->left);
                        preetrav(ptree->right);
                    }
                }

Can Any one help me to resolve the error …

There are few errors in your program.

  1. Use of conio. Standard gcc compiler not support conio.h. So, never use it again.

  2. No header file for malloc.

  3. On line number 115 you call preetrav() instead of pretrav() which is a syntax error.

And there is one more issue in memory declaration and typedef.

Here is the syntactically corrected


[1]. Don't know about the logic.


  [1]: http://ideone.com/MtzRkw
//