隐式声明函数'memset'[-Wimplicit-function-declaration]

9
我有以下的C代码:
#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;
}

当我运行代码时,我收到以下警告:
warning: implicit declaration of functionmemset[-Wimplicit-function-declaration]

我应该如何解决这个问题?

谢谢


5
memsetstring.h 中声明。 - Kninnug
6
请不要使用 gets 函数... - Steve Summit
1
@Michael:$ man memset - jsaji
2个回答

24

添加

#include <string.h>

在文件顶部。

这是因为头文件中包含了 memset 函数原型,编译器可以找到它。

避免使用 gets 函数... 使用 scanf 或者 fgets

这里看一下。


现在我有这个错误:警告:隐式声明函数'gets' [-Wimplicit-function-declaration] gets(buff); - Michael
@Michael:请查看这个答案,了解如何快速轻松地解决这类问题。 - Paul R
1
@Michael 你移除了 stdio 头文件吗?顺便避免使用那个函数... 使用 scanf 或者 fgets 替代。在这里看一下 HERE - LPs

2

添加

#include <string.h>

memset 函数可在 string.h 中找到。


现在我有这个错误:警告:隐式声明函数“gets”[-Wimplicit-function-declaration] gets(buff); - Michael

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接