The use of scanf and scanf_s in VS2013

Source: Internet
Author: User

scanf and scanf_s in VS2013 use in VS2013, each use scanf will error: This function or variable can be unsafe. Consider using scanf_s instead. To disable deprecation, use _crt_secure_no_warnings. See online Help for details.

Give two kinds of solutions, or use scanf_s, or use _crt_secure_no_warnings to deal with no error, why does it appear this reason?

scanf () does not check the bounds while reading, so it can cause a memory leak, so VS2013 provides a scanf_s () instead, which must be supplied to scanf_s when called to indicate how many characters are read, using scanf_s ("%c",& Letter,sizeof (letter)), otherwise, even if Ctrl+f7 and Ctrl+f5 Pass, the results of the program may differ greatly from what you expect.

If you do not want to use the scanf function, you can suppress the warning in the following two ways:
(1) Right-click on the project--attribute--c/c++--preprocessor--add _crt_secure_no_warnings to the preprocessor definition, then click OK to exit.
(2) at the top of the function definition: #define _CRT_SECURE_NO_WARNINGS, can also prohibit error warning.
Report

The use of scanf and scanf_s in VS2013

Related Article

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.