C Input/Output

There are different ways you can give input to program. For example, read input from screen console using keyboard or read input from file. 
Similarly there are different ways you can write output of program. For example, display output on screen console or write output in file.


We will discuss only basic input/output method which is generally used. i.e. Read input from screen console using keyboard and display output on screen console.

How to display output on screen?
There are different library functions to display data on screen. e.g. printf(), putchar(), putc()
Normally printf() is used to display data on screen. 

Syntax of using printf() is as below. 
printf(<format_specifier_string>, <comma_separated_list_of_variables>); 
<format_specifier_string> : is string having format notations specifying in which format you want to display data. Valid format notations are '%d', '%c', %f', '%s'. Each format specifier will be discussed as separate article.
<comma_separated_list_of_variables> : list of variables to be displayed corresponding to format notations specified in string.

Here is example of printf() function to display number using '%d' format specifier.

How to read input entered by keyboard?
There are different library functions to read data entered by keyboard. e.g scanf(), getchar(), getc()
Normally scanf() is used to display data on screen.
 
Syntax of using scanf() is as below. 
scanf(<format_specifier_string>, <comma_separated_list_of_address_of_variables>); 
<format_specifier_string> : is string having format notations specifying in which format you want to read data. Valid format notations are '%d', '%c', %f', '%s'. Each format specifier will be discussed as separate article.
<comma_separated_list_of_variables> : list of address of variables to be read corresponding to format notations specified in string.
Here is example of reading input using scanf() function.