The scanf s() function is a standard input function provided by Microsoft for the Visual Studio development tools that has the same functionality as the scanf function but is more secure, and has been provided by the Visual Studio tools since VC++ 2005.
Microsoft designed the ScanFS function with a deep integration of the Windows operating system, so it can only be used in the Windows environment, not on either macOS or Linux. This means that when the program uses the scanf s function, it cannot be directly used in the environment outside the Windows system without redundancy**, that is, the portability of the program becomes poor.
The difference between the scanf s function and the scanf function is that the former has an extra use forDetermine the buffer boundary, so the call to the function is basicallyscanf_s("%s",array,20)A more complex example of this function is shown in the following figure
As with the scanf function, the first parameter, the formatting, controls which symbol is used as the separator in the string, so the same symbol should be entered as the delimiter in the actual input. The scanf s function, in fact, is no different from the original scanf function except for one more parameter for specifying the buffer size.
As a matter of learning, you can learn about the use of scanfs, but as a work of the job, it is not recommended to use this function that is deeply coupled to the system environment. If you are concerned that scanf will cause a program error if it does not check the buffer boundary, you can deprecate it in favor of a more secure input function, or customize a safe version of the input function based on the scanf function prototype.
Users customize the implementation of the secure version of the input function according to the prototype of the scanf function, although it is the same as Microsoft's original scanf function, but the difference is that the source of the user-defined implementation function is part of the source of the whole program, which can be migrated with the program project file, while the scanf s function provided by Microsoft cannot.