Input/Output in 'C'
Most languages have facilities for input and output, built into the langauge. The 'C' language does not have built in statement of I/O. It has function to achieve the I/O. The standard I/O functions (scanf ( ), printf ( ) ) are normally performed by using the "stdio.h" header file. It has "conio.h" header file to perform console I/O functions (gets1), puts ( ). getchar, etc.
Standard I/O functions
1. Scanf ( ). This function allows to enter data from key board that will be formatted in a certain way. The general form of scanf ( ) statement is
scanf ("formatted string". List of addresses of variables);
For example -- scanf ("%d%f,"&a, &b);
Here & denotes the address of operator, this is necessary because the values received from keyboard must be dropped into variables corresponding to these addresses.
%d and %f are format specifiers which work as conversion characters. Format specifiers used in 'C' are as follows.
Format Specifier Data type
% d,% i Signed integer
%u Unsigned integer
%ld, %li Long integer
%lu unsigned long integer
%hd, %hi Short integer
% hu unsigned short integer
%lf, %le, %lg double
%Lf, %Le, %Lg Character
%s string, group of characters
printf ( ) -This information writes formatted data to screen. This function allows to supply the input in a fixed format and to obtain the output in the specified form. The printf ( ) function interprets the contents of the formats string.
printf ("formatted string", variables);
printf ("Average=%d percentage=%f", avg.per);
Here the % d and %f are conversion characters.
They tell printf ( ) to print the value of avg as an integer and per as a float .
printf ("Hello students
How are you");
, t are escape sequences. Escape sequences used in 'C' are
Escape Sequences Function
a beep (alert)
\ back slash
, Single quote
" Double quote
V Vertical tab
? Question mark