Search code examples
c

implicit declaration of function ‘memset’ [-Wimplicit-function-declaration]


I have the following c code:

#include<stdio.h>

int main(void)
{
    char buff[10];
    memset(buff,0,sizeof(buff));

    gets(buff);

    printf("\n The buffer entered is [%s]\n",buff);

    return 0;
}

When I run the code, I get the following warning:

warning: implicit declaration of function ‘memset’ [-Wimplicit-function-declaration]

Solution

  • Add

    #include <string.h>
    

    at the top of file.

    This because is the header file where the memset prototype can be found by compiler.

    Avoid using gets function... Use scanf or fgets instead.

    Take a look HERE