0
32kviews
What is difference between Unformatted and Formatted Data Input and output statements

Subject : Structured Programming Approach

Title : Fundamental of C Programming

Marks : 10M

1 Answer
0
682views

The difference between formatted and unformatted input and output operations is that in case of formatted I/O the data is formatted or transformed. Unformatted I/O transfers data in its raw form or binary representation without any conversions. Unformatted I/O is the most basic form of I/O and it is simple, efficient and compact.

getchar() and putchar()

getchar() function will read a single character from the standard input. The return value of getchar() is the first character in the standard input.The input is read until the Enter key is pressed, but only the first character in the input will be returned.

putchar() function will print a single character on standard output. The character to be printed is passed to putchar() function as an argument. The return value of putchar() is the character which was written to the output.

getchar() and putchar() functions are part of the standard C library header stdio.h

Example

#include <stdio.h>
 int main()
{ 
char ch;
printf("Input some character and finish by pressing the Enter key.\n");
ch = getchar();
printf("The input character is ");
putchar(ch);
return 0;
}

getch(), getche() and putch()

These functions are similar to getchar() and putchar(), but they come from the library header conio.h. The header file conio.h is not a standard C library header and it is not supported by compilers that target Unix. However it is supported in DOS like environments.

getch() reads a single character from the standard input. The input character is not displayed (echoed) on the screen. Unlike the getchar() function, getch() returns when the first character is entered and does not wait for the Enter key to be pressed.

getche() is same as getch() except that it echoes the input character. putch() writes a character that is passed as an argument to the console.

Formatted input and output statements

printf()

This function is used to print text as well as value of the variables on the standard output device (monitor), printf is very basic library function in c language that is declared in stdio.h header file.

Syntax :

printf(“message”);
printf(“message + format-specifier”,variable-list);

First printf() style printf the simple text on the monitor, while second printf() prints the message with values of the variable list.

scanf()

This function is used to get (input) value from the keyboard. We pass format specifiers, in which format we want to take input.

Syntax:

scanf(“format-specifier”, &var-name);
scanf(“fromat-specifier-list”, &var-name-list);

First type of scanf() takes the single value for the variable and second type of scanf() will take the multiple values for the variable list.

Please log in to add an answer.