warning: incompatible implicit declaration of built-in function 'strlen' and 'strcpy' [duplicate]

旧巷老猫 提交于 2019-12-01 23:42:06

问题


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:

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

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

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.

Used libraries:

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

Declaration of variables:

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.

Thanks in advance.


回答1:


You need to use

#include <string.h>

to get strcpy() and strlen()



来源:https://stackoverflow.com/questions/28044694/warning-incompatible-implicit-declaration-of-built-in-function-strlen-and-st

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!