1,105,384 Community Members

Difference betn getch(),getche(),getchar() functions

Member Avatar
comwizz
Light Poster
39 posts since Nov 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I would like to know what is the difference betn
getchar(),getch(), and getche() functions and which should be used in which conditions.
Thanks,
comwizz. :confused:

Member Avatar
Dave Sinkula
long time no c
4,852 posts since Apr 2004
Reputation Points: 2,398 [?]
Q&As Helped to Solve: 340 [?]
Skill Endorsements: 69 [?]
Team Colleague
 
0
 

getchar This is a standard function that gets a character from the stdin. getch This is a nonstandard function that gets a character from keyboard, does not echo to screen. getche This is a nonstandard function that gets a character from the keyboard, echoes to screen.

Use getchar if you want it to work on all compilers. Use getch or getche on a system that supports it when you want keyboard input without pressing [Enter].

And note that the return value of all three is int ! You need this to properly check for EOF.

Member Avatar
comwizz
Light Poster
39 posts since Nov 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

Thanks for the reply :)

Member Avatar
pavangavvala
Newbie Poster
2 posts since May 2009
Reputation Points: 15 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-2
 

wat is echo??

Member Avatar
Narue
Bad Cop
12,139 posts since Sep 2004
Reputation Points: 5,693 [?]
Q&As Helped to Solve: 1,537 [?]
Skill Endorsements: 81 [?]
Team Colleague
 
0
 

>wat is echo??
In this case, echo means that when you type a character, it prints to the screen so you can see what you typed.

Member Avatar
pavangavvala
Newbie Poster
2 posts since May 2009
Reputation Points: 15 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

>wat is echo??
In this case, echo means that when you type a character, it prints to the screen so you can see what you typed.

THANK U NARUE......:)

Member Avatar
rocky2008
Newbie Poster
10 posts since Jun 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

getch() returns the character you typed without displaying it on the screen.
getche() returns the character you typed by displaying(echoing) it on the screen.
and finally, getchar() works similarly and echos the character that u typed on the screen after "enter" is given.
hope you understood!!
all the best !! :)

I would like to know what is the difference betn
getchar(),getch(), and getche() functions and which should be used in which conditions.
Thanks,
comwizz. :confused:

Member Avatar
Aia
Nearly a Posting Maven
2,307 posts since Dec 2006
Reputation Points: 1,977 [?]
Q&As Helped to Solve: 236 [?]
Skill Endorsements: 20 [?]
 
1
 

Rocky2008> hope you understood!!
What part of post #2 did you not understand?

Member Avatar
patria987
Newbie Poster
9 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I would like to know what is the difference betn
getchar(),getch(), and getche() functions and which should be used in which conditions.
Thanks,
comwizz. :confused:

getche-displays the character that u have typed on the screen
getch-just returns the character that had been typed without displaying on the screen.
getchar-works similar as getche but needs an ENTER followed by the char typed...(macro version)

Member Avatar
Aia
Nearly a Posting Maven
2,307 posts since Dec 2006
Reputation Points: 1,977 [?]
Q&As Helped to Solve: 236 [?]
Skill Endorsements: 20 [?]
 
1
 

wat is echo??

The experience you get from people posting the same, over and over, in this thread.

People! this thread has been answered since post number two. And the only thing it could be added to it might be that unless you have a compelling reason to handicap your code with none standard functions, do not use getche() or getche().

Member Avatar
123.shravan
Newbie Poster
1 post since Dec 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

By : Shravan Aras <EMAIL SNIPPED>
Another interesting application of the getCh() function.
Also from my experience i have observed that sometimes the program fails to stop at

scanf(...)

. This happens because there is already some existing value in the buffer. To avoid this one can use

getCh();

to first clear the buffer and then use scanf function.
I am not completely sure of this process but has worked for me more than 90% of the times.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article