none
use scanf_s instead scanf

    Question

  • #include "stdafx.h"



    void main()
    {
        int x,r;
        x=0,r=0;
        printf("Please enter the first number : ");
        scanf("%d",&r);
        printf("please enter the 2nd number : ");
        scanf("%d",&x);

        printf(" after addition : %d \n", r+x);
        printf(" after subtraction : %d \n", r-x);
        int n;
        n=r*x;
        printf(" after multiplication : %d \n", n);
        n=r/x;
        printf(" after division : %d \n", n);


    }


    error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS



    Visual studio 2012  ultimate gives me this error  ( currently using vs 12 on Windows 8 RC)


    but Visual studio 2010 ultimate gives warning

    COde doesnt compile


    Saturday, September 15, 2012 8:10 PM

Answers

  • Visual Studio 2012 is stricter about deprecated functions than 2010 was.

    Rather than just advising you that you need to do something about your use of scanf, as Visual Studio 2010 did, it now FORCES you to do something about it.

    You need to switch to scanf_s or use _CRT_SECURE_NO_WARNINGS.


    Saturday, September 15, 2012 8:17 PM

All replies

  • Visual Studio 2012 is stricter about deprecated functions than 2010 was.

    Rather than just advising you that you need to do something about your use of scanf, as Visual Studio 2010 did, it now FORCES you to do something about it.

    You need to switch to scanf_s or use _CRT_SECURE_NO_WARNINGS.


    Saturday, September 15, 2012 8:17 PM
  • Thanks A lot Richie Hindle It helps me alot but why we cant use the simple scanf can u plzzzzz explain me in detail

    Wednesday, March 12, 2014 7:08 PM
  • As Richie said in his 18 month old message, there is a method to allow you to use scanf.  The fact that the default does not is a Microsoft decision unique to Visual C++ and not part of standard C or C++.  You might want to review http://www.cplusplus.com/forum/beginner/2300/ for additional details.
    Wednesday, March 12, 2014 10:34 PM
  • Does anyone can explain me how to use scanf_s or _CRT_SECURE_NO_WARNINGS?

    I tried to use it but when I debugg the program tell me that is and error or is a function or variable unsafe :( please help

    Wednesday, September 30, 2015 7:09 PM
  • Show your code and the complete error message.
    Wednesday, September 30, 2015 9:16 PM
  • Does anyone can explain me how to use scanf_s or _CRT_SECURE_NO_WARNINGS?

    I tried to use it but when I debugg the program tell me that is and error or is a function or variable unsafe :( please help

    Check in MSDN or Show your code .

    https://msdn.microsoft.com/en-us/library/w40768et.aspx?f=255&MSPPError=-2147217396

    For CRT macro add in your project property under preprocessor  or may be you can do something like , or use #ifdef inside your code 


    Thanks


    Rupesh Shukla


    • Edited by Pintu Shukla Wednesday, September 30, 2015 9:23 PM
    Wednesday, September 30, 2015 9:20 PM
  • Does anyone can explain me how to use scanf_s

    Assuming you're using Visual Studio/C++, then in the IDE editor place the cursor on
    scanf_s and press F1. You should get help for that function.

    - Wayne

    Thursday, October 1, 2015 12:26 AM