Welcome to graduate2professional.blogspot.com

Monday, May 11, 2009

Difference between Unformated I/O functions

getchar() :
The getchar() accepts a single charater from the keyboard.you have to specify the end of the input by pressing Enter key because the getchar() accepts bufferred input. This means that the input value is stored in a variable only aftr enter is pressed.
If more than one character is typed before pressing Enter,only the first character is accepted by the getchar() . The rest of the input character remain in th buffer while the first input character is returned by the getchar().

getch():
The getch() accepts a single character from the keyboard. The getch() accepts unbufferred input . This indicates that input is directly stored in a variable. Therefore, there is no need to press Enter key to specify the end of input.
The getch() returns the character you type, and this character is assigned to the char variable.

getche():
The character based input function getche() also accepts unbufferred input as a single character similar to the getch(). How ever , input to the getche() is echoed on the screen. The getche()returns the character accepted from the keyboard.

getc():
The getc() is used to accept a value for a character variable from a file. The file can be a disk file or the standard input device, which is the keyboard.

gets():
Finally, the gets function accepts a sequence of characters with embedded spaces. A sequence of characters with embedded spaces is called string. The end of the string is specified by pressing Enter.

1 comment: