Formatted Input-Output

C provides standard functions, scanf() and printf() , for performing formatted input and output respectively.

Theses functions accept,  parameters as,

The format specification string is a character string which specifies the

 

Formatted Output

 The function printf() is used for formatted output to output based on a format specification. The format specification string, along with the data to be output, are the parameters to the printf() function.

The syntax of the function printf() is:

printf( format, data1, data2, ....);

format is the format specification string.

This string will contain, for each variable to be output, a specification begins with the symbol % followed by a character called the conversion character.

For example:

printf ("%c", inp);

Here, first parameter is the format specification string.

Second parameter is the data name.

The character specified after % is called a conversion character, because it allows one data type to be converted to another type and printed.

The conversion characters and their meanings are:

d the data is converted to decimal.

c the data is taken as a character.

s the data is a string and characters from the string and printed until a NULL character is reached.

f the data is output as float or double with default precision 6.

 

Formatted Input

The function scanf() is used for formatted input from input and provides many of the conversion facilities of the function printf().

The syntax of the function scanf() is:

scanf (format, data1, data2,....);

The function scanf() reads and converts characters from the standard input according to the format specification string and stores the input in memory locations represented by the other arguments (data1, data2,..).

For example:

scanf ("%c%d", &sex, &enum);

Here first parameter is format specification string.

The second parameter is data names.

 

 

 

 

 

 

 

Copyright © 2008 Manikkumar. All rights reserved.