In C programming, input/output (I/O) functions are categorized into two main types: formatted and unformatted. The key difference lies in whether they use format specifiers to control how data is read or displayed.
1. Formatted Input/Output Functions:
These functions allow you to read and write data in a specific, user-defined format using format specifiers. They offer control over data types, precision, width, and alignment.
printf():- Used for formatted output to the console. It takes a format string and a variable number of arguments, displaying them according to the specified format.
Example: - printf( " Welcome to ittech");
scanf(): Used for formatted input from the console. It reads data according to a format string and stores it in specified variables.
Example: - scanf( " %d",&a);
Use of printf and scanf :
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
printf(" Enter the value of a and b :");
scanf("%d%d",&a,&b);
c=a+b;
printf(" The value of c = %d",c);
getch();
}
2. Unformatted Input/Output Functions:
These functions handle data as raw bytes, typically dealing with single characters or strings without requiring format specifiers. They are simpler and often used for basic character-level I/O.
getchar(): Reads a single character from the standard input (keyboard) and returns its ASCII value. It waits for the Enter key.
putchar(): Writes a single character to the standard output (console).
gets(): Reads an entire line of text (including spaces) from the standard input until a newline character is encountered.
puts(): Writes a string to the standard output, automatically appending a newline character at the end.
getch(): (from conio.h): Reads a single character directly from the keyboard without echoing it to the screen and without waiting for the Enter key.
getche(): (from conio.h): Reads a single character directly from the keyboard, echoes it to the screen, and does not wait for the Enter key.