Chh*_*rum 13 c windows tr24731 visual-studio c11
我创建了一个小应用程序,通过使用带参数的用户定义函数来查找最大数量.当我运行它时,它会显示此消息
错误1错误C4996:'scanf':此函数或变量可能不安全.请考虑使用scanf_s.要禁用弃用,请使用_CRT_SECURE_NO_WARNINGS.详细信息请参见在线帮助.
我该怎么做才能解决这个问题?
这是我的代码
#include<stdio.h>
void findtwonumber(void);
void findthreenumber(void);
int main() {
int n;
printf("Fine Maximum of two number\n");
printf("Fine Maximum of three number\n");
printf("Choose one:");
scanf("%d", &n);
if (n == 1)
{
findtwonumber();
}
else if (n == 2)
{
findthreenumber();
}
return 0;
}
void findtwonumber(void)
{
int a, b, max;
printf("Enter a:");
scanf("%d", &a);
printf("Enter b:");
scanf("%d", &b);
if (a>b)
max = a;
else
max = b;
printf("The max is=%d", max);
}
void findthreenumber(void)
{
int a, b, c, max;
printf("Enter a:");
scanf("%d", &a);
printf("Enter b:");
scanf("%d", &b);
printf("Enter c:");
scanf("%d", &c);
if (a>b)
max = a;
else if (b>c)
max = b;
else if (c>a)
max = c;
printf("The max is=%d", max);
}
Run Code Online (Sandbox Code Playgroud)
use*_*467 12
听起来这只是一个编译器警告.
用法scanf_s
可防止可能的缓冲区溢出.
请参阅:http: //code.wikia.com/wiki/Scanf_s
关于为什么scanf
会有危险的好解释:scanf的缺点
因此,作为建议,可以尝试更换scanf
用scanf_s
或禁用编译器警告.
抑制错误的另一种方法:在C/C++文件的顶部添加此行:
#define _CRT_SECURE_NO_WARNINGS
Run Code Online (Sandbox Code Playgroud)