void search(char*** p, int numOfWords, int* pNumOfDefArr){
int i, j, index;
char* word = (char*)malloc(WORD_SIZE * sizeof(char));
for (i = 0; i < N; i++) //just clearing the screen
printf("\n");
printf("Hello and thank you for filling Dictionary 1.0 with new words!!\n");
printf("Which word are you looking for??\n");
gets(word);
fix_word(word, 0);
while (strcmp(word, "Exit")){
index = (search_word(p, word, 0, numOfWords - 1, 0));
if (index < 0)
printf("Unknown word!!!!!!\n");
else{
for (j = 0; j < pNumOfDefArr[index]; j++)
printf("%s\n", *(*(p + index) + 1 + j));
}
free(word);
char* word = (char*)malloc(WORD_SIZE * sizeof(char));
printf("Looking for another word?\n");
gets(word);
fix_word(word, 0);
}
printf("Farewell!!\n");
On the debugger I can see that on the 10th line: while (strcmp(word, "Exit"))
the value of word is
changing from "asd" to "Error reading characters of string." Why is that?
Here's the code for the fix_word()
function:
void fix_word(char* pword, int j){
if (*(pword + j) != '\0'){
if (j == 0 && (*(pword + j) >= 'a' && *(pword + j) <= 'z')){
*pword -= N;
j++;
}
else if (*(pword + j) >= 'A' && *(pword + j) <= 'Z'){
*(pword + j) += N;
j++;
}
else
j++;
fix_word(pword, j);
}
}