1.运行报错严重性 代码 说明 项目 文件 行 禁止显示状态错误: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.
2.关闭项目属性“SDL检查”
3.顺利运行通过
4.附上图片的完整测试代码(猜数字)
#include "stdio.h"
#include "conio.h"
void main()
{
int Password=0,Number=0,price=58,i=0;
while( Password != 12345 )
{
if( i >= 3 )
return;
i++;
puts("Please input Password: ");
scanf("%d",&Password);
}
i=0;
while( Number!=price )
{
do{
puts("Please input a number between 1 and 100: ");
scanf("%d",&Number);
printf("Your input number is %d\n",Number);
}while( !(Number>=1 && Number<=100) );
if( Number >= 90 )
{
printf("Too Bigger! Press any key to try again!\n");
}
else if( Number >= 70 && Number < 90 )
{
printf("Bigger!\n");
}
else if( Number >= 1 && Number <= 30 )
{
printf("Too Small! Press any key to try again!\n");
}
else if( Number > 30 && Number <= 50 )
{
printf("Small! Press any key to try again!\n");
}
else
{
if( Number == price )
{
printf("OK! You are right! Bye Bye!\n");
}
else if( Number < price )
{
printf("Sorry,Only a little smaller! Press any key to try again!\n");
}
else if( Number > price )
printf(" Sorry, Only a little bigger! Press any key to try again!\n");
}
getch();
}
}
还有其他方法(来自网络)
方法2:在程序最前面加,#pragma warning(disable:4996);
方法3:scanf改为scanf_s;
方法4:在程序最前面加,“#define_CRT_SECURE_NO_WARNINGS;”或者“ #define _CRT_SECURE_NO_DEPRECATE;”
方法5:在项目属性 ‘c/c++ ’命令行添加:
“/D _CRT_SECURE_NO_WARNINGS ”。