Home c Why does scanf_s function in Visual Studio stop working in C when...

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

Author

Date

Category

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

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions