C Commands

Sid Kraft 21 Reputation points
2020-08-24T20:27:38.413+00:00

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!

Developer technologies C++
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Colin Robertson 96 Reputation points
    2020-08-24T20:38:19.76+00:00

    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.


  2. Jeanine Zhang-MSFT 11,356 Reputation points Microsoft External Staff
    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;  
    }  
    

    20087-8251.png

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

    0 comments No comments

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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.