Why does the scanf s function in Visual Studio stop working in C when using "%s"

Why does the 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 click enter, and I see the message "Shutdown".

Author: Ainar-G, 2015-08-05

2 answers

Because scanf_s requires specifying the size of all buffers passed to it.

scanf_s("%s", name, 40);
 6
Author: Pavel Mayorov, 2015-08-05 18:35:22

You must specify the _countof (имя переменной куда считываешь) parameter, for example:

scanf_s("%s",&name,_countof(name));
 1
Author: System Engineer, 2018-03-25 17:27:35