According to the scanf_s documentation, the argument you're trying to fill with a value needs to be a pointer to a variable of the appropriate type. Unless Variable
is a pointer, you might want to try &Variable
instead.
C Commands
Well, using the Visual C 2019, tried all of the following, will not work! Trying to input an integer number from the keyboard, tried:
-scanf_s("%I",Variable);
-scanf_s("%d",Variable);
-scanf_s("%u",Variable);
All give assertion errors, not sure why they do not work, Help!
3 answers
Sort by: Most helpful
-
Colin Robertson 96 Reputation points
2020-08-24T20:38:19.76+00:00 -
Jeanine Zhang-MSFT 9,181 Reputation points Microsoft Vendor
2020-08-25T05:59:49+00:00 Here is my code. No assertion error is given, and it works.
#include<stdio.h> int main(void) { int Variable; printf("Please enter number:"); scanf_s("%i", &Variable); printf("%i\n", Variable); return 0; }
>>Tried scanf_s("%i",&Variable); same result, pointer does not work either!
I'm appreciate that if you could provide us with a sample of your code to reproduce the issue, we will provide you with better help. And could you please describe in detail in detail what "not working" means.
Best Regards,
Jeanine Zhang
-
Sid Kraft 21 Reputation points
2020-08-26T00:59:16.707+00:00 Re-Ran the application again, the assert interrupt is being caused by the statement following the scanf_s on a "for" statement? Have to find out why. Thanks for the input so far, will update when I find out.