3

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.

rampy
  • 33
  • 1
  • 1
  • 4

1 Answers1

7

You need to use

#include <string.h>

to get strcpy() and strlen()

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
Gopi
  • 19,784
  • 4
  • 24
  • 36