' strcpy':_CRT_SECURE_NO_WARNINGS

时间:2017-12-26 14:50:13

标签: c++

*****当我运行此代码时,我收到一些错误。 ' strcpy':,' fscanf':,' fopen':_crt_secure_no_warnings 我怎么解决呢? **

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;

}

1 个答案:

答案 0 :(得分:1)

msvc中的警告告诉你,这些功能比其他功能更危险。

您可以通过将 _crt_secure_no_warnings 添加到项目属性中的预处理器设置来禁止它。