- C has 6 popular data input and output library functions. They are getchar, putchar, printf, scanf, gets and puts.
- These functions handle data transfer between computer and the input/output device (keyboard,monitor)
- The functions getchar and putchar allow single characters to be transferred into and out of the computer.
- The functions printf and scanf allow the transfer of single characters, numerical values and strings
- The functions gets and puts handle input and output of strings.
- To use these functions in a program the standard input output header file stdio.h must be included in the program.
- The getchar() function reads a single character from the input device(keyboard)
The character entered on the keyboard is read by the getchar function and assigned to the character variable c.
- If an end of file condition is found when reading a character using getchar, the value of symbolic constant(-1) will be returned.
- The putchar() function display a single c character on the standard output device.
The character stored in the variable c is displayed in the monitor.
- scanf function used to read any numerical values, single characters or strings.
- The function returns the number of data items that have been entered successfully.
- Table shows the conversion character and the data item meaning
Conversion character Meaning c Single character d decimal integer e,f,g Floating point value h Short integer i decimal, hexa decimal or octal integer o octal integer u unsigned decimal integer x Hexadecimal integer s String [...] String include whitespace characters
- The arguments may be variables or array.
- Each variable name must be preceded by an ampersand(&). Array name should not begin with &.
- If 2 or more data items are entered they must be separeted by whitespace characters[blank space (or) new line (or) tab].
- While reading a string that include whitespace characters use . specify the whitespace characters inside the 
- Example: Read a string which contains only capital letters and blank space
here if the input is given as WELCOME TO C then text contain WELCOME TO C. If the input is given as Welcome To C then only the single letter W would be assigned to text
- If the characters with in the brackets are given after circumflex(^) operator then the scanf will read all the characters except the characters in the 
The program will read any characters(maximum 49 characters) until the newline is pressed.
- It is possible to limit the number of characters read by specifying a maximum field width for that data item. To do that an unsigned integer integer indicating the field width is placed with in the control string between the percent sign(%) and the conversion character.
- The data item may contain fewer characters than the specified field width but cannot exceed the specified field width. If we give more characters than the specified field width the leftover characters are incorrectly interpreted as a next data item
- If the input is given as 12 34 56 then a=12 b=34 c=56.
- If the input is given as 123456789 then a=12 b=34 c=56
- If the input is 123 4 5678 then a=12 b=3 c=4
- Example 2:
- if the input is 555.55 then f=555.500000
- If the input is 456789.555 then f=45678.000000
- if the input is 55555.555 then f=55555.00000
- If there is no whitespace present between the conversion characters in the scanf function then the whitespace characters with in the input data will be interpreted as a data item.
If x y z is given as input then a=x b= (blankspace) c=y
- To avoid reading the blankspace use %1s instead of %c
If x y z is given as input then a=x b=y c=z or we can write the scanf as scanf("%c %c %c",&a,&b,&c);
- Unrecognized characters within the control string are expected to be matched by the same characters in the input data. The unrecognized characters are read but not assigned to any variable but if the characters are not present then the scanf function will terminate.
- Example: If the input is given as a * b then only a=a b=b. if the input is given as a b then the function is stop executing as * is not given as input. so a is assigned to a . b is Null