警告:内置函数“strlen"和“strcpy"的隐式声明不兼容

警告:内置函数“strlen

问题描述:

我刚刚完成了我的刽子手游戏,作为最后一步,我正在进行一些代码清理和优化,但我似乎无法理解为什么我会收到以下两个警告:

I just finnished my hangman game and as a last step I am doing some code cleanup and optimization, but I can't seem to understand why I receive the following two warnings:

警告:内置函数 'strlen' 的隐式声明不兼容

warning: incompatible implicit declaration of built-in function 'strlen'

警告:内置函数'strcpy'的隐式声明不兼容

warning: incompatible implicit declaration of built-in function 'strcpy'

使用它们的代码在这里:

The code in which they are used is here:

for(i = 1; i <= random; i++)
    fgets(word, 100, f);
fclose(f);

for(i = 0; i < strlen(word); i++)
    if(word[i] == '\n')
        word[strlen(word)-1] = '\0';

lungime = strlen(word);
strcpy(word2, word);

我所做的是使用 fgets 从文件中读取一个随机单词.在此之后,我删除了 fgets 自动放置的 '\n'.最后,我把word2中的word复制了一份.

What I done was to read a random word from a file, using fgets. After this, I removed the '\n' which fgets automatically puts. Finally, I made a copy of the word in word2.

使用的库:

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

变量声明:

int random, n = 0, i, j, lengh, tries = 5, ok = 0, error = 0;;
char word[100], word2[100], tried_letters[50], auxch;

注意:在我的程序中一切正常,但我收到了我想摆脱的两个警告.

Note: everything works perfect in my program, but I receive those two warnings which I would like to get rid of.

提前致谢.

需要使用

#include <string.h>

得到strcpy()strlen()