C Input output function
C programming language provides many of the built-in functions to read given input and write data on screen, print or in any file. Two commonly used functions for I/O (Input/Output) are printf() and scanf().
The scanf() function reads formatted input from standard input (keyboard) whereas the printf() function sends output to the standard output (screen).
Input means to feed some data in to program. An input in the form of a file or from the command line.C programming provides a set of built-in functions to read the given input .
Output means to display some data on screen, printer, or in any file. C programming provides a set of built-in functions to output the data on the computer screen as well as to save it in text or binary files. C programming language provides a set of built-in functions to output required data.
There are commanly scanf() and printf() Functions
The int scanf(const char *format, ...) function reads the input from the standard input stream stdin and scans that input according to the format provided.
The int printf(const char *format, ...) function writes the output to the standard output stream stdout and produces the output according to the format provided.
Example : C Integer Input/Output
printf("Enter an integer value: ");
printf("Number = %d",i);
Enter an integer value: 4
Number = 4
getchar() & putchar() functions
The getchar() function reads a character from the terminal and returns it as an integer. This function reads only single character at a time. You can use this method in the loop in case you want to read more than one characters. The putchar() function prints the character passed to it on the screen and returns the same character. This function puts only single character at a time. In case you want to display more than one characters, use putchar() method in the loop.
void main( )
printf("Enter a character");
gets() & puts() functions
The gets() function reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF (end of file). The puts() function writes the string s and a trailing newline to stdout.
printf("Enter the string");
gets( str );
puts( str );