免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
warning: the 'gets' function is dangerous and should not&nbs

在Linux下,使用

gets(cmd)

函數(shù)報錯:warning: the 'gets' function is dangerous and should not beused.

 

解決辦法:采用

fgets(cmd,100,stdin);//100為size

問題解決!

 

fgets從stdin中讀字符,直至讀到換行符或文件結(jié)束,但一次最多讀size個字符。讀出的字符連同換行符存入緩沖區(qū)cmd中。返回指向cmd的指針。

gets把從stdin中輸入的一行信息存入cmd中,然后將換行符置換成串結(jié)尾符NULL。用戶要保證緩沖區(qū)的長度大于或等于最大的行長。

 

gets的詳細(xì)解釋:

char * gets ( char * str );//Get string fromstdin

Reads characters from stdin and stores them as a string intostr  until a newline character ('\n') or theEnd-of-File is reached.
The ending newline character ('\n') is not included in thestring.

A null character ('\0') is automatically appended after the lastcharacter copied to str to signal the end of the C string.

Notice that gets does notbehave exactly as fgets does with stdin as argument: First,the ending newline character is not included with gets while withfgets it is. And second, gets does not let you specify a limit on howmany characters are to be read, so you must be careful with thesize of the array pointed by str to avoid bufferoverflows.

 

說明:紅色部分很好地解釋了“the'gets' function is dangerous and should not beused”這個warning的原因。

參考鏈接:http://www.cplusplus.com/reference/clibrary/cstdio/gets/

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
c語言 運行cmd 查詢某個文件夾內(nèi)文件名并且輸出
LAMBDA strip trailing characters recursive
TelloPy-develop-0.7.0源碼閱讀.1
Trim - Function Summary
運算符重載_連接兩個字符串_1
MouseGestures2目前的鼠標(biāo)手勢和鼠標(biāo)手勢方向
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服