Why does the scanf_s function in Visual Studio 2013 stop using the C language when using "% s"?

char name[40]; scanf_s("%s", name); 

Then, when I entered the data into the console, I press enter, and I see the message “Termination of work”.

    2 answers 2

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

     scanf_s("%s", name, 40); 

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

     scanf_s("%s",&name,_countof(name)); 
    • The _countof type is not the same, you need unsigned transfer. - Qwertiy