Scanf_s problem

Allen 21 Reputation points
2021-01-04T15:07:42.683+00:00

53342-image.png

When I built resolution, it has no error, as I input "dmf" random three character, this happened.

Developer technologies C++
{count} votes

Accepted answer
  1. RLWA32 49,536 Reputation points
    2021-01-04T15:27:10.71+00:00

    Documentation is your friend. The docs here - scanf-s-scanf-s-l-wscanf-s-wscanf-s-l say "Unlike scanf and wscanf, scanf_s and wscanf_s require you to specify buffer sizes for some parameters. Specify the sizes for all c, C, s, S, or string control set [] parameters. The buffer size in characters is passed as an additional parameter. It immediately follows the pointer to the buffer or variable."

    So the code should be -

    #include <stdio.h>  
      
    int main()  
    {  
        char a, b, c;  
        scanf_s("%c%c%c", &a, 1, &b, 1, &c, 1);  
        return 0;  
    }  
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.