-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.

  • You're passing the wrong type as it's second argument. Doesn't the compiler warn about this? (If not, you might need to increase the warning level, assuming msvc will warn about mismatches between scanf formats and arguments at all like gcc and clang will) – Shawn Jun 25 '19 at 23:23
  • 1
    `scanf_s("%d", &repeat);`... – David C. Rankin Jun 25 '19 at 23:31

1 Answers1

0

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

https://learn.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.

v01d
  • 189
  • 1
  • 12