关于比较输入两个数并输出最大值的C语言问题 (在VS2012下运行)#include "stdafx.h"int _tmain(int argc,_TCHAR* argv[]){\x09int max(int x,int y);\x09int a,b,c;\x09scanf("%d,%d",&a,&b);\x09c=max(a,b);\x09printf("max=%d\n",c);\x09r

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 08:56:59
关于比较输入两个数并输出最大值的C语言问题 (在VS2012下运行)#include

关于比较输入两个数并输出最大值的C语言问题 (在VS2012下运行)#include "stdafx.h"int _tmain(int argc,_TCHAR* argv[]){\x09int max(int x,int y);\x09int a,b,c;\x09scanf("%d,%d",&a,&b);\x09c=max(a,b);\x09printf("max=%d\n",c);\x09r
关于比较输入两个数并输出最大值的C语言问题 (在VS2012下运行)
#include "stdafx.h"
int _tmain(int argc,_TCHAR* argv[])
{
\x09int max(int x,int y);
\x09int a,b,c;
\x09scanf("%d,%d",&a,&b);
\x09c=max(a,b);
\x09printf("max=%d\n",c);
\x09return 0;
}
int max(int x,int y)
{
\x09int z;
\x09if (x>y) z=x;
\x09else z= y;
\x09return z;
}
1>------ 已启动生成:项目:ConsoleApplication4,配置:Debug Win32 ------
1> ConsoleApplication4.cpp
1>c:\users\lenovo\documents\visual studio 2012\projects\consoleapplication4\consoleapplication4\consoleapplication4.cpp(11):error 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.
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\stdio.h(290) :参见“scanf”的声明

关于比较输入两个数并输出最大值的C语言问题 (在VS2012下运行)#include "stdafx.h"int _tmain(int argc,_TCHAR* argv[]){\x09int max(int x,int y);\x09int a,b,c;\x09scanf("%d,%d",&a,&b);\x09c=max(a,b);\x09printf("max=%d\n",c);\x09r
原因是Visual C++ 2012中,由于担心使用那些不进行参数检测的C库函数,会造成内存异常,微软改写了同样功能的函数,使这些新的函数(就是那些带有"_s”后缀的函数)更安全.

可以用新的安全函数(如scanf_s)替换原来的旧函数(如 scanf).