scanf() and scanf_s()
Both scanf() and scanf_s() functions can be used to read data from standard input.
The secure versions (those with the _s suffix) of the scanf() family of functions require that a buffer size parameter be passed preceding each parameter of type c, C, s, S or [.
The width specification is separate and distinct from the buffer size argument required by the secure versions of these functions (i.e., scanf_s(), wscanf_s(), etc.). In the following example, the width specification is 20, indicating that up to 20 characters are to be read from the input stream. The buffer length is 21, which includes room for the possible 20 characters plus the null terminator:
char str[21];
scanf_s("%20s", str, 21);