The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
Unformatted input and output functions are only work with character data type. Unformatted input and output functions do not require any format specifiers. Because they only work with character data type.
The getchar() function reads character type data form the input. The getchar() function reads one character at a time till the user presses the enter key.
#include <stdio.h> //header file section #include <conio.h> int main() { char c; printf("Enter a character : "); c = getchar(); printf("\nEntered character : %c ", c); return 0; }
Here, getchar() reads the input from the user and display back to the user.
The getch() function reads the alphanumeric character input from the user. But, that the entered character will not be displayed.
#include <stdio.h> //header file section #include <conio.h> int main() { printf("\nHello, press any alphanumeric character to exit "); getch(); return 0; }
The above program will run until you press one of many alphanumeric characters. The key pressed by you will not be displayed.
getche() function reads the alphanumeric character from the user input. Here, character you entered will be echoed to the user until he/she presses any key.
#include <stdio.h> //header file section #include <conio.h> int main() { printf("\nHello, press any alphanumeric character or symbol to exit \n "); getche(); return 0; }
The above program will run until you press one of many alphanumeric characters. The key pressed by you will be echoed.
putchar() function prints only one character at a time.
#include <stdio.h> //header file section #include <conio.h> int main() { char c = 'K'; putchar(c); return 0; }
Here, variable c is assigned to a character 'K'. The variable c is displayed by the putchar(). Use Single quotation mark ' ' for a character.
The putch() function prints any alphanumeric character.
#include <stdio.h> //header file section #include <conio.h> int main() { char c; printf("Press any key to continue\n "); c = getch(); printf("input : "); putch(c); return 0; }
The getch() function will not echo a character. The putch() function displays the input you pressed.
The gets() function can read a full string even blank spaces presents in a string. But, the scanf() function leave a string after blank space space is detected. The gets() function is used to get any string from the user.
#include <stdio.h> //header file section #include <conio.h> int main() { char c[25]; printf("Enter a string : "); gets(c); printf("\n%s is awesome ",c); return 0; }
The gets() function reads a string from through keyboard and stores it in character array c[25]. The printf() function displays a string on the console.
The puts() function prints the charater array or string on the console. The puts() function is similar to printf() function, but we cannot print other than characters using puts() function.
#include <stdio.h> //header file section #include <conio.h> int main() { char c[25]; printf("Enter your Name : "); gets(c); puts(c); return 0; }
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019