*****when I run this code ,I get some error. 'strcpy': ,'fscanf':,'fopen': _crt_secure_no_warnings how can I solve it? **
else if ( (*root)->frequency > minHeap->array[0]. frequency ) {
minHeap->array[ 0 ]. root->indexMinHeap = -1;
minHeap->array[ 0 ]. root = *root;
minHeap->array[ 0 ]. root->indexMinHeap = 0;
minHeap->array[ 0 ]. frequency = (*root)->frequency;
// delete previously allocated memoory and
delete [] minHeap->array[ 0 ]. word;
minHeap->array[ 0 ]. word = new char [strlen( word ) + 1];
strcpy( minHeap->array[ 0 ]. word, word );
minHeapify ( minHeap, 0 );
}
}
fscanf:
void printKMostFreq(FILE* fp, int k)
{
MinHeap* minHeap = createMinHeap(k);
// Create an empty Trie
TrieNode* root = NULL;
// A buffer to store one word at a time
char buffer[MAX_WORD_SIZE];
// Read words one by one from file. Insert the word in Trie and Min Heap
while (fscanf(fp, "%s", buffer) != EOF)
insertTrieAndHeap(buffer, &root, minHeap);
// The Min Heap will have the k most frequent words, so print Min Heap nodes
displayMinHeap(minHeap);
}
fopen:
int main(){
int k = 5;
FILE *fp = fopen("file.txt", "r");
if (fp == NULL)
printf("File doesn't exist ");
else
printKMostFreq(fp, k);
return 0;
}