liunx 切换用户中gets用什么代替

Award-winning computer security news
Free tools
About the author
Paul Ducklin is a passionate security proselytiser. (That's like an evangelist, but more so!) He lives and breathes computer security, and would be happy for you to do so, too.
Follow him on Twitter: @duckblog
Recommended reads
Paul Ducklin
Paul Ducklin
Paul Ducklin
Paul Ducklin
Paul Ducklin
Paul Ducklin在Linux下,使用
函数报错:warning: the 'gets' function is dangerous and should not be used.
解决办法:采用
fgets(cmd,100,stdin);//100为size
问题解决!
fgets从stdin中读字符,直至读到换行符或文件结束,但一次最多读size个字符。读出的字符连同换行符存入缓冲区cmd中。返回指向cmd的指针。gets把从stdin中输入的一行信息存入cmd中,然后将换行符置换成串结尾符NULL。用户要保证缓冲区的长度大于或等于最大的行长。
gets的详细解释:
char * gets ( char * str );//Get string from stdin
Reads characters from stdin and stores them as a string into str&&until a newline character ('\n') or the End-of-File is reached.The ending newline character ('\n') is not included in the string.A null character ('\0') is automatically appended after the last character copied to str to signal the end of the C string.
Notice that gets does not behave exactly as fgets does with stdin as argument: First, the ending newline character is not included with gets while with fgets it is. And second,&gets does not let you specify a limit on how many characters are to be read, so you must be careful with the size of the array pointed by str to avoid buffer overflows.
说明:红色部分很好地解释了&the 'gets' function is dangerous and should not be used&这个warning的原因。
参考链接:/reference/clibrary/cstdio/gets/
阅读(...) 评论()}

我要回帖

更多关于 liunx 常用命令 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信