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

Question:

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:

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

scanf_s("%s", name, 40);
Scroll to Top