I'm getting a compiler error in one of my .c's that I don't understand.
I'm getting

Tree.c:  In function 'newTree':
Tree.c:301:  error: expected declaration or statement at end of input

What I don't understand is that newTree and line 301 are completely separate functions. I can get the line error to move up and down a few lines by commenting out sections of code.


Any tips for the deleteNode() would be greatly appreciated :)

#include<stdio.h>
#include<stdlib.h>
#include"TreeInfo.h"
#include"Tree.h"

/*
typedef struct TreeNode
{
    struct TreeNode *L;
    TreeInfoT info;
    struct TreeNode *R;
} *TreeNodeT;


 
typedef struct Tree
{
    TreeNodeT root;
} *TreeT;


/*******************************************************************************
 *
 *    "Private" node functions
 *
 ******************************************************************************/



TreeNodeT newNode(TreeInfoT data)
{
  TreeNodeT temp = (TreeNodeT) malloc(sizeof(struct TreeNode));
  temp->info = data;
  temp->L = NULL;
  temp->R = NULL;
  
  return temp;

}

TreeInfoT findNode(TreeNodeT node, TreeInfoT data)
{
  if (node == NULL)
    fprintf(stderr,"\nfindNode passed null node.\n");

  int stat = compareToTreeInfo(data, node->info);

  if(stat == 0)
    return node->info;

  else if (stat < 0)

    if(node->L == NULL)
      return NULL;
    else 
      findNode(node->L, data);


  else
    if (node->R == NULL)
      return NULL;
    else 
      findNode(node->R, data);


}


void insertNode(TreeNodeT node, TreeNodeT inNode)
{
  if (node == NULL)
    return;

  int stat = compareToTreeInfo(inNode->info,node->info);

  if (stat == 0)
    {
      fprintf(stderr,"\nduplicate found in insertNode.\n");
      //      return NULL;
    }
  else if (stat < 0)
    {
      //if leaf -- insert
      if (node->L == NULL)
	node->L = inNode;
      //else keep searching
      else
	insertNode (node->L, inNode);
    }
  else
    {
      // if leaf -- insert
      if (node->R == NULL)
	node->R = inNode;
      //else keep searching
      else
	insertNode(node->R, inNode);
    }

}
  
void displayNode(TreeNodeT root)
{
  if(root == NULL)
    return;

  displayNode(root->L);
  displayTreeInfo(root->info);
  displayNode(root->R);
}

TreeNodeT deleteNode(TreeNodeT node, TreeInfoT data)
{
  
  int stat = compareToTreeInfo(data, node->info);

  switch(stat)
    {

      //found node to delete
    case 0:
      //check for child cases
      break;
      
      //look to node->R
    case 1:
      if(node->R == NULL)
	{
	  fprintf(stderr,"\ndeleteNode -- node not found\n");
	  return NULL;
	}
      deleteNode(node->R, data);
            
      break;
     
      //look to node->L
    case -1:
      if(node->L == NULL)
	{
	  fprintf(stderr,"\ndeleteNode -- node not found\n");
	  return NULL;
	}
      deleteNode(node->L, data);

      break;

    default:
      fprintf(stderr,"deleteNode -- Invalid switch case.\n");

    }//switch

 return ;
}//deleteNode()


void freeNode(TreeNodeT node)
{
  free(node);
}




/*******************************************************************************
 *
 *  "Public"  Tree functions
 *
 ******************************************************************************/

/*
 * Returns a pointer to a new empty Tree
 * If memory cannot be allocated, returns a NULL pointer
 */
TreeT newTree()
{
  TreeT temp = (TreeT) malloc(sizeof(struct Tree));
  if (temp == NULL)
    {
      fprintf(stderr,"newTree malloc failed");
      return NULL;

  temp->root == NULL;
  return temp;
}

/*
 * Returns a pointer to a node
 * If not found, return a NULL pointer
 * Parameters: tree and node to be found
 */
TreeInfoT findTree(TreeT tree, TreeInfoT data)
{
  if (tree == NULL)
    {
      fprintf(stderr,"findTree passed null tree");
      return NULL;
    }
  return findNode(tree->root, data);

}

/*
 * Creates node with the provided info
 * Inserts the node into the correct position in the tree
 */
/*
  if(tree !=NULL)
     if(
 */
void insertTree(TreeT tree, TreeInfoT data)
{
  if (tree == NULL)
    {
      fprintf(stderr,"insertTree passed null tree");
      exit(1);
    }
  else if (tree->root == NULL)
    {
      TreeNodeT node = newNode(data);
      tree->root = node;
    }

  if (findTree(tree, data) == NULL )
    {
      TreeNodeT node = newNode(data);
      
      insertNode(tree->root, node);
    }
      
      
}

/*
 * Removes the node containing the matching names
 * Parameters: tree and info to be removed
 */
/*
  need a TreeNodeT deleteNode(TreeNodeT, TreeInfoT) that is recursive
  {
  find node
  decide if two or less children
  
  if 2 children
     find max of left subtree
     copy info of max_left to node to delete
     delete(Node, info_max_left)


  if one or less child
     if (q->left == NULL)
     parent->ptr = q->right
     else
     parent->ptr = q->left

     free q

     return left or right back to parent
 */
void removeTree(TreeT tree, TreeInfoT data)
{
  if(tree!= NULL)
    removeNode(tree->root, data);
}

/*
 * Dislpays all the nodes in the tree using an inorder traversal
 */
/*
  if (ptr!=NULL)
inOrder(ptr->left);
displayInfo(ptr)
inOrder(ptr->right)
 */
void displayTreeInorder(TreeT tree)
{
  if(tree != NULL)
    displayNode(tree->root);
  return;
}

/*
 * Frees the memory used by all the nodes in the tree
 * Frees the memory by the tree
 * Does NOT free the memory used by the "info"
 */
/*
post order
same as display
 */
void freeTree(TreeT tree)
{
  /*
  if(tree != NULL)
    {
      freeTree(tree);
      freeTree(tree);
      //      freeNode(tree);
      }*/
 
}

Nvm, found the mismatched braces. Sorry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.