Exclude unsafe function warnings in vs2005

Source: Internet
Author: User
Tags printf

The following code:

#include <stdio.h>
#include <minmax.h>
int main( )
{
  int a,b,c;
  scanf("%d,%d",&a,&b);
  c=max(a,b);
  printf("max=%d",c);
  return 0;
}

When compiling with VS2005, you will encounter such a warning:warning C4996: ' scanf ' was declared deprecated

In fact, the detailed meaning of warning C4996 is: ' scanf ': This function or variable may is unsafe. Consider using scanf_s instead. To disable deprecation, use _crt_secure_no_warnings. The scanf statement is considered unsafe in VS2005 and allows you to replace it with scanf_s.

Know the reason, the solution is convenient, as long as the #include <stdio.h> before adding #define _crt_secure_no_deprecate or scanf function modified to scanf_s can. Specifically as follows:

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <minmax.h>
int main( )
{
  int a,b,c;
  scanf("%d,%d",&a,&b);
  c=max(a,b);
  printf("max=%d",c);
  return 0;
}

Or

#include <stdio.h>
#include <minmax.h>
int main( )
{
  int a,b,c;
  scanf_s("%d,%d",&a,&b);
  c=max(a,b);
  printf("max=%d",c);
  return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.