C programming I/O function: scanf( )

scanf( ) is the standard library function that is used for precise input formatting.

syntax of scanf( ) function:

scanf( format-control-string, other-arguments );

Format control string in scanf( ) function describes the input format and other argument are pointers to list of variables.

Each conversion specifier starts with % sign and ends with a conversion specifier.

We can perform the following formatting using scanf( ) function

Inputting certain characters from input.

Skipping certain characters from input.

Inputting all types of data.

Conversion specifiers for scanf( ) function are same as printf( ).

Let’s discuss some important features of scanf( ) function.

Reading character using scan set

We can only read certain characters from the input stream using scan set, set of characters enclosed in the square bracket [ ] that is preceded by a percent % sign.

The characters from the input stream that matched the character in scan set are stored in the array, otherwise, stops inputting characters when a character that is not stored in scan set is encountered.

On the other hand, if we want to omit certain characters from input stream we should place a care (^) sign before the scan characters. This is called an inverted scan set.