I made a couple of changes in the code, basically replacing the search function prototype,
Code:
TreeNodePtr search(char *key, TreeNodePtr leaf)
now its ok, I am getting two syntax errors in the function search()
here is the function:
Code:
TreeNodePtr search(char *key, TreeNodePtr leaf)
{
//printf("Enter Employee name:");
//gets(key);
//If the leaf is pointing to something
if(leaf!=NULL)
{
/* Allocate a temporary structure to help with our compareData() call */
EMP tmpData;
strcpy(tmpData->fname, key);
switch (compareData(leaf->data, tmpData))
{
case 0:
//If the values are equal, return the node
return leaf;
case -1:
//If the inputed value is less then the leaf's value, search left side for the inputed value
return search(key,leaf->leftPtr);
case 1:
//If the inputed value is greater then the leaf's value, search right side for the inputed value
return search(key,leaf->rightPtr);
}
}
else
{
//If the leaf isn't pointing to anything, return 0;
return NULL;
}
}
errors:
operations.c:109: error: invalid type argument of ‘->’
Code:
strcpy(tmpData->fname, key);
operations.c:110: error: incompatible type for argument 2 of ‘compareData’
Code:
switch (compareData(leaf->data, tmpData))
and here is the compareData function:
Code:
int compareData( EMP *firstVal, EMP *secondVal)
{
switch (strcmp(firstVal->fname, secondVal->fname))
{
/* The two first names match */
case 0:
switch (strcmp(firstVal->lname, secondVal->lname))
{
/* The last name ALSO matches */
case 0:
break;
/* The firstVal's lastname is greater than secondVal's lastname */
case 1:
return 1;
break;
/* The firstVal's lastname is less than secondVal's lastname */
case -1:
return -1;
break;
}
break;
/* The firstVal's firstname is greater than secondVal's firstname */
case 1:
return 1;
break;
/* The firstVal's firstname is less than secondVal's firstname */
case -1:
return -1;
break;
}
}