运行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