成功解决:‘scanf‘: This function or variable may be unsafe. Consider using scanf_s instead

编程知识 更新时间:2023-05-02 05:30:35

运行C程序时报错:

错误 C4996 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

原代码:

scanf(" %c", &c);


scanf换成scanf_s后调试程序

scanf_s(" %c", &c);


调试程序时报警告

警告 C6064 缺少“scanf_s”的整型参数(对应于转换说明符“2”)

scanf_s在使用%c和%s读入字符或字符串时,应在地址参数后附加一个缓冲区边界值。

scanf_s(" %c", &c, sizeof(c));


再次运行程序,警告消失,问题解决

成功解决:‘scanf’: This function or variable may be unsafe. Consider using scanf_s instead 的问题

欢迎小伙伴讨论,如有错误请在评论区评论或发私聊消息,谢谢你。

更多推荐

成功解决:‘scanf‘: This function or variable may be unsafe. Consider using scanf_s in

本文发布于:2023-04-26 06:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/95eb984d51a73b7b7db82dfdd4901767.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:function   scanf   variable   scanf_s   unsafe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 104550文章数
  • 26215阅读数
  • 0评论数