Linux 下使用C语言 gets()函数报错
在Linux下,使用
gets(cmd)
函数报错: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的原因。
参考链接:http://www.cplusplus.com/reference/clibrary/cstdio/gets/
Linux 下使用C语言 gets()函数报错的更多相关文章
- Linux下使用JDK11部署Nacos启动报错:Could not find or load main class
Linux下使用JDK11部署Nacos 错误日志 /nacos/jdk-11.0.12/bin/java -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize ...
- Linux下Python3.5使用pyqt5.11报错 ImportError: /usr/local/lib/python3.5/dist-packages/PyQt5/QtCore.so: undefined symbol: PySlice_AdjustIndices 解决方法
我用的Linux自带的是Python3.5版本,运行pip3 install PyQt5, 下载的是PyQt5.11,运行PyQt5程序会报错: ImportError: /usr/local/lib ...
- linux下安装apache最常见的报错解决
报错如下: Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, ...
- VS中C语言scanf函数报错
在VS中创建C项目使用scanf方法时会如下报错 解决方案 方法1:文件中设置 在第一行设置代码 #define _CRT_SECURE_NO_WARNINGS 或者添加警告忽略 #pr ...
- 在linux下运行apt-get update 时,报错/var/lib/apt/lists/lock
在运行apt-get update 时,报下面的错误: E: 无法获得锁 /var/lib/apt/lists/lock - open (11: Resource temporarily unavai ...
- Linux下rm -rf删除文件夹报错_ Device or resource busy
1.错误信息 rm: cannot remove `speechd-centos_6.2-prtl-pred-mf34/modules/t2p/py/third/g2p/.nfs00000000039 ...
- 1、linux下mysql5.5.20安装过程报错汇总
1.Access denied for user 'root'@'localhost' (using password: YES) 这个提示是因为root帐户默认不开放远程访问权限,所以需要修改一下相 ...
- Linux下Java运行.class文件,报错找不到或无法加载主类
classpath配置的错误,所以找不到.class文件. 原先的etc/profile中的classpath配置 export CLASSPATH=$JAVA_HOME/lib/tools.jar ...
- windows下的c语言和linux 下的c语言以及C标准库和系统API
1.引出我们的问题? 标准c库都是一样的!大家想必都在windows下做过文件编程,在linux下也是一样的函数名,参数都一样.当时就有了疑问,因为我们非常清楚 其本质是不可能一样的,源于这是俩个操作 ...
随机推荐
- Python scapy 实现一个简易 arp 攻击脚本
原文链接:http://www.jianshu.com/p/df5918069612 scapy 是 python 写的一个功能强大的交互式数据包处理程序,可用来发送.嗅探.解析和伪造网络数据包,常常 ...
- ubuntu 添加用户
sudo useradd 用户名 创建用户 sudo passwd 用户名 修改用户密码 添加sudo权限 sudo usermod -aG sudo(要添加的用户组,也可以是root) 用户名 su ...
- 将输入流InputStream转换为String
public static String convertStreamToString(InputStream is) { /* * To convert the InputStream to Stri ...
- 2017.3.27 集成modeler后的一些主要路径(持续更新)
1.设计器访问路径 项目名:wfs_web edtor-app和modeler.html的存放位置:webapp/designer/editor-app app-cfg.js中根路径设置:'conte ...
- java debug
java debug 模式下各button作用 F5:跳入方法 Step Into F6:向下逐行调试 Step Over F7:跳出方法 Step Return F8:直接跳转到下一个断点 D ...
- Sql 复习3之存储管理
一.事务管理 单个工作单元称为事务,我们将若干条sql命令组合在一起,形成存储过程.触发器等,利用存储过程和触发器可以进行事务管理. 二.编程基础介绍 主要有:函数.程序设计语句等. 程序设计语句: ...
- VueJS定义组件规则
Vue.js 组件 组件(Component)是 Vue.js 最强大的功能之一,组件可以扩展 HTML 元素,封装可重用的代码. 组件系统让我们可以用独立可复用的小组件来构建大型应用,几乎任意类型的 ...
- [转]如何用C++实现一个LRU Cache
[转自http://hawstein.com/posts/lru-cache-impl.html] LRU是Least Recently Used的缩写,意思是最近最少使用,它是一种Cache替换算法 ...
- 开启Java远程调试
在JDK启动时,加入 -Xrunjdwp:transport=dt_socket,address=9900,server=y,suspend=n -Dcom.sun.management.jmxrem ...
- WARN util.NativeCodeLoader: Unable to load native-hadoop l... using builtin-java classes where applicable(附编译脚本)
WARN util.NativeCodeLoader: Unable to load native-hadoop l... using builtin-java classes where appli ...