-1

*****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;

}

C.Dogan
  • 1
  • 1
  • 1
    *"'strcpy': ,'fscanf':,'fopen': _crt_secure_no_warnings"* - That's the error message? Really? Which compiler? – Christian Hackl Dec 26 '17 at 14:58
  • 2
    Why are you using C "strings" in a C++ program in the first place? – Jesper Juhl Dec 26 '17 at 15:00
  • 1
    "FILE *fp = fopen("file.txt", "r");" - prefer [fstream](http://en.cppreference.com/w/cpp/header/fstream) in C++. In fact, most of your code looks like C compiled with a C++ compiler interspaced with a bit of old-style (pre-C++11) C++. You would do yourself a favour by reading up on modern C++ - there are better ways to do most things you are doing. – Jesper Juhl Dec 26 '17 at 15:10
  • how to copy 2 string string data type , c++ without using strcpy @JesperJuhl – C.Dogan Dec 26 '17 at 15:40
  • @C.Dogan You can construct a [std::string](http://en.cppreference.com/w/cpp/string) directly [from a const char*](http://en.cppreference.com/w/cpp/string/basic_string/basic_string) (see nr. 5). – Jesper Juhl Dec 26 '17 at 15:44

1 Answers1

1

It is a warning in msvc which is telling you the functions are a bit more risky than others.

You can suppress it by adding _crt_secure_no_warnings to the preprocessor settings in the project properties.

EvilTeach
  • 28,120
  • 21
  • 85
  • 141