Introduction
Dennis Ritchie wanted C to remain compact.
C deliberately omitted I/O functionalities from its definition.
Explore how I/O is managed in C and how printf() and scanf() are used.
Types of I/O
Different operating systems have their I/O facilities.
System programmers link the C Compiler with OS-specific I/O facilities.
C Compilers come with standard I/O libraries.
Console I/O Functions
Two categories: Formatted and Unformatted
Formatted functions allow customization of input and output.
Example functions in each category.
Formatted Console I/O Functions
printf() and scanf() are formatted functions.
printf() format string and format specifiers.
Examples of format specifiers.
Format Specifications
Format specifiers for different data types.
Optional format specifiers for field width and precision.
Examples of using field width and precision.
Escape Sequences
Escape sequences are special characters in format strings.
Examples of escape sequences like \n and \t.
Usage of Escape Sequences
Demonstration of how escape sequences work.
Common escape sequences listed.
Custom Format Specifiers
printf() attempts to perform specified conversions.
Examples of conversions with sensible and weird results.
scanf() Function
scanf() reads and formats data from the keyboard.
Format string and list of addresses of variables.
Address of variables is needed for storing input.
sprintf() and sscanf() Functions
sprintf() stores output in a character array.
sscanf() reads characters from a string.
Useful for in-memory conversions.
Unformatted Console I/O Functions
Functions for handling single characters.
getch(), getche(), getchar(), and fgetchar().
putch(), putchar(), and fputchar() for character output.
Usage of getch(), getche(), and getchar()
getch() and getche() read characters without waiting for Enter.
putchar() echoes the typed character.
fgetchar() is a macro for reading characters.
Usage of putch() and putchar()
putch() and putchar() for character output.
They print one character at a time.
gets() and puts() Functions
gets() reads a string from the keyboard.
Solves issues with scanf() for string input.
puts() outputs a string to the screen.
Example of gets() and puts()
Demonstration of using gets() and puts().
Summary
No C keyword for I/O; use standard library functions.
Formatted and unformatted console I/O functions.
Formatted functions allow customization.
Format specifiers and escape sequences.
Unformatted functions work faster.
Example functions and their purposes.