Advertisement



< Prev
Next >



C - Formatted I/O Functions




C language provide us console input/output functions. As the name says, the console input/output functions allow us to -
There are two kinds of console input/output functions -



Formatted input/output functions


Formatted console input/output functions are used to take one or more inputs from the user at console and it also allows us to display one or multiple values in the output to the user at the console.


Some of the most important formatted console input/output functions are -

Functions Description
scanf()
This function is used to read one or multiple inputs from the user at the console.

printf()
This function is used to display one or multiple values in the output to the user at the console.

sscanf()
This function is used to read the characters from a string and stores them in variables.

sprintf()
This function is used to read the values stored in different variables and store these values in a character array.



Q : Why these functions are called formatted console input/output functions?

While calling any of the formatted console input/output functions, we must use a specific format specifiers in them, which allow us to read or display any value of a specific primitive data type. Let's see what are these format specifiers.


Advertisement




Format specifiers in console formatted I/O functions


Some of the most commonly used format specifiers used in console formatted input/output functions are displayed in the table below -

Format Specifiers Description
%hi

Format specifier used to read or display a signed short integer value or short integer value.

%hu

Format specifier used to read or display an unsigned short integer value.

%d

Format specifier used to read or display a signed int integer value.

%u

Format specifier used to read or display a unsigned int integer value.

%ld

Format specifier used to read or display a long integer value or signed long integer value.

%lu

Format specifier used to read or display a unsigned long integer value.

%c

Format specifier used to read or display a char, character value. Format specifier %hhi is used to display a signed numerical value.

%c

Format specifier used to read or display a unsigned char, character value. Format specifier %hhu is used to display a signed numerical value.

%f

Format specifier used to read or display a float, floating point value.

%lf

Format specifier used to read or display a double, floating point value.

%Lf

Format specifier used to read or display a long double, floating point value.

%s

Format specifier used to read or display a string value, to be stored in a char[] array.






Optional specifiers within a format specifier


We could specify two more optional specifiers within each format specifier, such as integer value and a sign.


Let's see examples of how to use two of the most commonly used formatted console input/output functions, scanf and printf() in our next article.




Please share this article -





< Prev
Next >
< Array of structures
scanf() and printf() function >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement

Notifications



Please check our latest addition

PYTHON


Advertisement