warning: incompatible implicit declaration of built-in function 'strlen' and 'strcpy'
14,002
You need to use
#include <string.h>
to get strcpy()
and strlen()
Author by
Admin
Updated on June 07, 2022Comments
-
Admin almost 2 years
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.