formatted and unformatted input and output functions
Managing Input and Output Operations:
1 . Introduction: -
- In C programming, input and output (I/O) operations are handled through standard library functions defined in <stdio.h>.
- Input means taking data from the user (keyboard, file, etc.) into the program.
- 'Output' means displaying data (on screen, file, etc.).
- C does not have built-in I/O keywords. instead, it uses functions like printf( ), scanf( ), getchar( ), putchar( ), etc.
- C treats all Input/Output as streams. Stream is a sequence of bytes flowing between the program and devices (keyboard, screen, files, etc.).
- There are three standard streams:
a) stdin — standard input
(keyboard)
b) stdout — standard output
(screen / console)
c) stderr — standard error
(screen, for errors messages)
2. reading a Character: -
- We can use the function getchar( ) to read a single character from the user.
Example: -
output: -
3 . Writing a Character: -
- We can use the function putchar() to display a single character on the screen.
Example: -
output: -
4 . Non-formatted input/output functions: -
- Non-formatted Input/output functions handle characters and strings directly without formatting.
- Commonly used functions:
a) getchar( ) → Reads a single character.
b) putchar( ) → Writes a single character.
c) gets( ) → Reads a string .
d) puts( ) → Writes a string.
Example: -
output: -
5 . formatted input/output functions: -
- Formatted Input/Output functions allow structured input and output with formatting.
- Commonly used functions:
a) scanf( ) → Reads input in specified format.
b) printf( ) → Displays output in specified
format.
Example: -
output: -