Prev Next
getche() function in C:
getche() function is a function in C programming language which waits for any character input from keyboard and it will also echo the input character on to the output screen. Please find below the description and syntax for above file handling function.
File operation
|
Declaration & Description
|
getche() | Declaration: int getche(void); This function waits for any character input from keyboard. And, it will also echo the input character on to the output screen. |
Example program for getche() function in C programming language:
This is a simple Hello World! C program. After displaying Hello World! in output screen, this program waits for any character input from keyboard. After any single character is typed/pressed, this program returns 0. But, please note that, getche() function will wait for any keyboard input (and press ENTER) and it will display the given input character on output screen immediately after keyboard input is entered.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <stdio.h> int main() { char flag; /* Our first simple C basic program */ printf("Hello World! "); printf("Do you want to continue Y or N"); flag = getche(); // It waits for keyboard input. if (flag == 'Y') { printf("You have entered Yes"); } else { printf("You have entered No"); } return 0; } |
Output:
Hello World!
Do you want to continue Y or N Y You have entered Yes |
Note:
To use getch(), getche() functions, you need to include #include <conio.h> header file which is a non-standard header file.
Other Inbuilt file handling functions in C programming language:
C programming language offers many other inbuilt functions for handling files. They are given below. Please click on each function name below to know more details, example programs, output for the respective file handling function.
File handling functions
|
Description
|
fopen () | fopen () function creates a new file or opens an existing file. |
fclose () | fclose () function closes an opened file. |
getw () | getw () function reads an integer from file. |
putw () | putw () functions writes an integer to file. |
fgetc () | fgetc () function reads a character from file. |
fputc () | fputc () functions write a character to file. |
gets () | gets () function reads line from keyboard. |
puts () | puts () function writes line to o/p screen. |
fgets () | fgets () function reads string from a file, one line at a time. |
fputs () | fputs () function writes string to a file. |
feof () | feof () function finds end of file. |
fgetchar () | fgetchar () function reads a character from keyboard. |
fprintf () | fprintf () function writes formatted data to a file. |
fscanf () | fscanf () function reads formatted data from a file. |
fputchar () | fputchar () function writes a character onto the output screen from keyboard input. |
fseek () | fseek () function moves file pointer position to given location. |
SEEK_SET | SEEK_SET moves file pointer position to the beginning of the file. |
SEEK_CUR | SEEK_CUR moves file pointer position to given location. |
SEEK_END | SEEK_END moves file pointer position to the end of file. |
ftell () | ftell () function gives current position of file pointer. |
rewind () | rewind () function moves file pointer position to the beginning of the file. |
getc () | getc () function reads character from file. |
getch () | getch () function reads character from keyboard. |
getche () | getche () function reads character from keyboard and echoes to o/p screen. |
getchar () | getchar () function reads character from keyboard. |
putc () | putc () function writes a character to file. |
putchar () | putchar () function writes a character to screen. |
printf () | printf () function writes formatted data to screen. |
sprinf () | sprinf () function writes formatted output to string. |
scanf () | scanf () function reads formatted data from keyboard. |
sscanf () | sscanf () function Reads formatted input from a string. |
remove () | remove () function deletes a file. |
fflush () | fflush () function flushes a file. |