2016-01-20 80 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