scanf_s() Function in C

This function is specific to Microsoft compilers. It is the same as scanf, except it does not cause buffer overload. scanf_s() function is more secure than scanf() function as it provides an additional parameter to specify the buffer size that can avoid buffer overflow.

Syntax

int scanf_s(const char *format [argument]...);

Parameters

  • stream: Pointer to the File object that identifies the stream.
  • format: It is a string that contains the type specifier(s).
  • … (ellipsis): It indicates that the function accepts a variable number of arguments.

Note: Here we can specify the buffer size and actually control the limit of the input so that the whole application don’t crash due to memory overflow.

Return Value

  • On success, the function returns the number of values read.
  • In the case of an input failure, before any data could be successfully read, EOF is returned.

Inbuilt library functions for user Input | sscanf, scanf_s, fscanf_s, sscanf_s

The C Programming Language provides various Inbuilt Library Functions for User Input. In this article, we will learn about sscanf, scanf_s, fscanf_s, sscanf_s Library Functions in C.

Similar Reads

1. sscanf() Function in C

sscanf() is used to read formatted input from the string. Both scanf() and sscanf() functions are similar, the only difference between them is that scanf() function reads input from the user from standard input like a keyboard, and sscanf() function reads input from a string and stores the input in another string....

2. scanf_s() Function in C

...

Why to use scanf_s()?

This function is specific to Microsoft compilers. It is the same as scanf, except it does not cause buffer overload. scanf_s() function is more secure than scanf() function as it provides an additional parameter to specify the buffer size that can avoid buffer overflow....

3. fscanf_s() Function in C

scanf just reads whatever input is provided from the console. C does not check whether the user input will fit in the variable that you’ve designated. If you have an array called color[3] and you use scanf for the string “Red”, it will work fine but if user enters more than 3 characters scanf starts writing into memory that doesn’t belong to colour array....

4. sscanf_s() Function in C

...

Contact Us