I'm building a program that searches a tree for a name and then outputs their phone number. The program all works well I need to make it ignore the case of the search input when searching for a name.
I've done this by building a function to make strings lowercase and then calling this function when comparing the strings.
However, its all gone tits up and I've been raking my brains as to whats not right. Its something to do with the way I've calling my data structure i would suspect.
Any input would be greatly appreciated.
Code:
char *search( Tree *root, entry *what ) {
if( root == NULL ) {
return "Not Found";
} else if( strcmp(makelower(what->name), makelower(root->thisnode.name)) == 0) {
return root->thisnode.number;
} else if( strcmp(makelower(what->name), makelower(root->thisnode.name)) < 0 ) {
return search(root->left, what);
} else {
return search(root->right, what);
}
}
char *makelower(char *s) {
int n = strlen(s);
while (n > 0) {
if (s[n] <= 90 && s[n] >= 65) {
s[n] = s[n] - 32;
}
n++;
}
return strdup(s);
}