How to fix scanf_s functions in c?

-1

I'm trying to make a "tik-tak-toe" program and I tried to make it repeat, so I used a while loop. I ask the user type 1 for yes, and 2 for no. After that I had a scanf_s statement. For some reason visual studios 2015 is giving me a warning right when I type one for yes and press enter :

"Unhandled exception at 0x5D14B5F2 (ucrtbased.dll) in tick-tack-toe.exe: 0xC0000005: Access violation writing location 0x00000001." This warning does not show up when I pressed 2 to for no.

I used the debugger to find what was going wrong and I found that it was the scanf_s statement. I've tried to make it just a regular scanf statement but when I run the code is says that the code failed and that the error is,

"'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." I've went all over the internet and tried everything I found but nothing worked. :(

int repeat = 1;
while(repeat == 1){
    printf("do you want to play again \n 1.yes \n 2.no \n");
    scanf_s("%d", repeat);
}

I expect my code to go back to the start when I press 1 but instead it bugs up.

c
visual-studio-2015
asked on Stack Overflow Jun 25, 2019 by Nik Brusilovski

1 Answer

0

Please read carefully prototypes of these functions, specifically look at how to pass parameters:

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/scanf-s-scanf-s-l-wscanf-s-wscanf-s-l?view=vs-2019

Hint: You passing 'repeat' wrong way.

Also note:

"Unhandled exception at 0x5D14B5F2

That's not a warning, more like program crash / fatal error.

answered on Stack Overflow Jun 25, 2019 by v01d

User contributions licensed under CC BY-SA 3.0