I keep getting these 2 compilation errors in my program.
word_freq_binary.c: In function 'getWord'
word_freq_binary.c:36:4: warning: implicit declaration of function ‘toLower’
str[n++] = toLower(ch);
^
tmp/ccYrfdxE.o: In function 'getWord':
word_freq_binary.c:(.text+0x91): undefined reference to `toLower'
collect2: error: ld returned 1 exit status
I have defined as follows:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MaxWordSize 20
The function with the error is:
int getWord(FILE *in, char str[])
{
//stores the next word if any, in str; word is converted
//to lowercase
//return 1 if a word is found; 0, otherwise
char ch;
int n = 0;
while (!isalpha(ch = getc(in)) && ch != EOF);
if (ch == EOF)
{
return 0;
}
str[n++] = tolower(ch);
while(isalpha(ch = getc(in)) && ch != EOF)
if (n < MaxWordSize) {
str[n++] = toLower(ch);
}
str[n] = '\0';
return 1;
} //end getWord
My main function is:
int main() {
int getWord(FILE *, char[]);
TreeNodePtr newTreeNode(NodeData);
NodeData newNodeData(char[], int);
TreeNodePtr findOrInsert(BinaryTree, NodeData);
void inOrder(FILE *, TreeNodePtr);
char word[MaxWordSize + 1];
FILE *in = fopen("./c/IronHeel.txt", "r");
FILE *out = fopen("./c/IronHeelOutput.txt", "w");
BinaryTree bst;
bst.root = NULL;
while(getWord(in, word) != 0) {
if (bst.root == NULL)
{
bst.root = newTreeNode(newNodeData(word, 1));
}
else
{
TreeNodePtr node = findOrInsert(bst, newNodeData(word, 0));
node -> data.wordCount++;
}
}
fprintf(out, "\nWords Frequency\n\n");
inOrder(out, bst.root);
fprintf(out, "\n\n");
fclose(in);
fclose(out);
system ("PAUSE");
return 0;
}
I have no idea why I am getting this error as I have included ctype.h.
As somebody already told you, put tolower function in lower case, as C is case sensitive. Also second comment was also useful: using camel style in C code is not common.
The problem is that the linker cannot find a reference to the symbol toLower, because this one is not declared either implemented. Is why you also get the first warning.