2016-01-20 81 views
-3

我有下面的C代码:的功能 'memset的'[-Wimplicit函数声明]隐式声明

#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 function ‘memset’ [-Wimplicit-function-declaration] 

我应该如何解决问题?

感谢

+5

'memset'在声明'string.h' – Kninnug

+6

请请请不要使用'gets' ... –

+1

@迈克尔:$男人memset的 – Griffin

回答

1

在文件的顶部添加

#include <string.h> 

这是因为头文件中memset原型可以通过编译器找到。

避免使用获取功能...使用scanffgets代替。

看看HERE

+0

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

+0

@Michael:请参阅[本答案](http://stackoverflow.com/a/2506036/253056),以了解如何快速轻松地解决这些类型的问题。 –

+1

@Michael你删除了stdio include吗? BTW避免使用该功能...使用[scanf](http://www.tutorialspoint.com/c_standard_library/c_function_scanf.htm)或[fgets](http://www.tutorialspoint.com/c_standard_library/c_function_fgets.htm )代替。看看[这里](http://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used) – LPs

0

添加

#include <string.h> 

memset的是string.h中提供

+0

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