-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetchar function.cpp
42 lines (28 loc) · 1.01 KB
/
getchar function.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* C++ getchar() function explanation with example:-
*) C++ provides one function called getchar() to read user inputs.This function reads the next character from stdin!
*) The syntax of the getchar() function is as below :-
int getchar ( void );
*) Parameters and return types:-
This function doesn’t take any parameter.
On success, it returns one integer value.
On failure, it returns EOF. Note that if it reads end-of-file, EOF is returned and sets the stdin eof indicator.
For error or failure, EOF is returned and sets the stdin error indicator. EOF is returned in both cases.
*) Header to include:-
This is actually a C library used for input/output operations. It is defined in the _cstdio _(C standard input-output library) header of C++.
Here is an example:-
*/
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int ch;
cout << "Enter a string:- " << endl;
do
{
ch = getchar();
cout << "Reading--" << ch << "or" << char(ch) << endl;
}
while(ch!='\n');
return 0;
}