Formatted Functions
Formatted functions allow input or output data to format according to user’s requirements. The input function scanf() and output function printf() are formatted functions.
Formatted Input
Formatted input refers to an input data that has been arranged in a particular format. scanf() is input Formatted functions.
Example
Write a program to show the usage of whitespace character in scan() function.
#include<stdio.h> #include<conio.h> int main() { int n1; char ch; printf("Enter a number:"); scanf("%d",&n1); printf("Enter a character:"); scanf("%c", &ch); printf("Number:%d\t Character: %c",n1,ch); getch(); return 0; } OUTPUT Enter a number : 10 Enter a character :R Number: 10 Character: R
Formatted Output
Formatted output functions are used to display or store data in a particular specified format. The printf() is an example of formatted output function.
Example
Write a program to display an integer, a float and a string value using single printf() function.
#include<stdio.h> #include<conio.h> int main() { int n=10; float f=45.6; char name []= "Ram"; printf("integer=%d\tfloat=%f\string=%s", n,f,name); getch(); return 0; } OUTPUT integer =10 float = 45.599998 string = Ram
Unformatted Functions
Unformatted functions do not allows the user to read or display data in desired format. These type of library functions basically deal with a single character or a string of character. The functions getchar(), putchar(), gets(), puts(), getch(), getche(), putch() are considered as unformatted functions.
Example
Write a program to read a string with multiple words using gets() function and display on the screen using puts() function.
#include<stdio.h> #include<conio.h> int main() { char name[20]; printf("Enter Your name"); gets(name); printf("Your name is"); puts(name); return 0; } OUTPUT Enter Your name: Bipin Tiwari Your name is : Bipin Tiwari