So I have a Binary search tree where each node holds a struct called WORD which contains three fields: a dynamically allocated string (word), an int indicating the number of times the word is found in a text file (count) and an int indicating the number of times it was searched by the user (search_count).
I am trying to complete a search function whereby the user inputs an integer and all words that appear that amount of times are printed to the screen and continues to do so until the user enters -1.
The problem I am having is when I try to run the loop to do this..
It prints the first result indefinitely..
Any and all feedback is appreciatedCode:void searchFreq (BST_TREE *list) { WORD target, *wordPtr; printf("Enter a frequency, enter -1 to exit: "); scanf("%d", &target.count); while(target.count != -1) { wordPtr = (WORD*)BST_Retrieve (list, &target); if(!wordPtr) printf("No words with such a frequency were found\n"); else{ while(wordPtr != NULL){ wordPtr->search_count++; printf("Word: %s\n", wordPtr->word); printf("Frequency: %d\n", wordPtr->count); printf("Search count: %d\n", wordPtr->search_count); wordPtr = (WORD*)BST_Retrieve (list, wordPtr); } } printf("Enter a frequency, enter -1 to exit: "); scanf("%d", &target.count); } }



LinkBack URL
About LinkBacks


