如何禁止警告“gets()已被弃用”? [英] how to supress warning "gets() is deprecated"?

查看:1858
本文介绍了如何禁止警告“gets()已被弃用”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试使用 gets()函数输入字符串时,我的编译器会给我警告,如下所示。如何摆脱这一点。

  test.c:27:2:warning:'gets'已弃用(在/ usr处声明) /include/stdio.h:638)[-Wdeprecated-declarations] 
gets(temp);


解决方案使用 fgets 代替:

  fgets(temp,sizeof(temp),stdin); 

gets 已被弃用,因为它很危险,可能会导致缓冲区溢出。


everytime i try to input my string using gets() function, my compiler gives me warning like shown below. how to get rid of this. what am i doing wrong?

test.c:27:2: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(temp);
^

解决方案

Use fgets instead:

fgets(temp, sizeof(temp), stdin);

gets is deprecated because it's dangerous, it may cause buffer overflow.

这篇关于如何禁止警告“gets()已被弃用”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆