So I building a spell checker and I have this as my TrieNode class:
class TrieNode{
public:
bool isWord;
char word[100][20];
TrieNode* letter[alphabetSize];
I have an insert method inside my Trie class which is:
void insert(TrieNode* root, char* wordInsert);
I was able to insert the letters of char* word into my trie
This is what I have for my insert function:
void Trie::insert(TrieNode* root, char* wordInsert) {
TrieNode* currentNode = root;
int wordLength = strlen(wordInsert);
for (int i = 0; i < wordLength; i++) {
//strcpy(currentNode->word[i], currentNode->letter);
int index = wordInsert[i]- 'a';
if(!currentNode->letter[index]){
currentNode->letter[index] = new TrieNode();
}
currentNode = currentNode->letter[index];
}
currentNode->isWord = true;
}
Now I want to insert the current->letter[i] into my other char* array in my TrieNode class called word
I tried doing
strcpy(currentNode->word, currentNode->letter[i])
but I get an error saying :
No matching function for call to 'strcpy'
How would I be able to get the elements from the letter array into the array called word which is also in my TrieNode class
Aucun commentaire:
Enregistrer un commentaire