Why does scanf_s function in Visual Studio 2013 stop working in C when using “% s”.
char name [40];
scanf_s ("% s", name);
Here, when I entered the data in the console, I press enter, and I see the message “Termination of work”.
Answer 1, authority 100%
Because scanf_s
requires you to specify the size of all buffers passed to it.
scanf_s ("% s", name, 40);
Answer 2, authority 17%
You must specify the _countof parameter (the name of the variable where you read it)
, for example:
scanf_s ("% s", & amp; name, _countof (name));