
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Differences Between getc, getchar, getch and getche Functions
All of these functions are used to get character from input and each function returns an integer signifying the status code as well.
Following are the important differences between getc(), getchar(), getch() and getche() functions.
getc()
getc() can read characters from any stream. Returns EOF on failure.
Syntax
int getc(FILE *stream);
getchar()
getchar() can read characters from standard input only.
Syntax
int getchar();
getch()
getch() can read characters from standard input but it does not use any buffer and returns immidately without waiting for enter key pressed.
Syntax
int getch();
getche()
getche() behaves similar to getch() as it can read characters from standard input and it does not use any buffer and returns immidately without waiting for enter key pressed. Only differnce is that it prints the character as well.
Syntax
int getch();
Example
#include <stdio.h> #include <conio.h> int main() { printf("%c", getc(stdin)); printf("%c", getchar()); printf("%c", getch()); printf("%c", getche()); return 0; }
Output
A B C D EE
Advertisements