how to supress warning “gets() is deprecated”? [duplicate]

落花浮王杯 提交于 2020-01-21 05:17:25

问题


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);
^

回答1:


Use fgets instead:

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

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



来源:https://stackoverflow.com/questions/26192934/how-to-supress-warning-gets-is-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!