What is the difference between getc() and getchar() functions?
Anybody can explain with example?
What is the difference between getc() and getchar() functions?
Anybody can explain with example?
> What is the difference between getc() and getchar() functions?
Functionally - nothing
getc might be a macro, whereas getchar is always a function
getc will read from any FILE*, whereas getchar always reads from stdin
I thought that getchar was normally implemented something like this...
int getchar(void)
{
return getc(stdin);
}
wouldn't that make it the better candidate for a macro salem?
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
putc() putchar()
getc() getchar()
The only difference, is the 'char' ones default to read from stdin, where as the 'c' ones require you specify a file stream. Usually if I recall correctly, a macro. Many 'functions' are implemented as macros.
Quzah.
Hope is the first step on the road to disappointment.
incase of getchar()
the program waits for a character
followed by "enter" key
but incase of getch()
"enter" key is not needed .
as soon as u press a character , the program
continues .
avinna
I believe this is incorrect. There is no ANSI standard for reading a single key STROKE. What you're seeing, unless I'm mistaken, is implementation specific. In C, because of the way input is handled, there is, unless changed, no ANSI method of grabbing a single keystroke. Your result is likely compiler specific.incase of getchar()
the program waits for a character
followed by "enter" key
but incase of getch()
"enter" key is not needed .
as soon as u press a character , the program
continues .
avinna
Quzah.
Hope is the first step on the road to disappointment.
Thank you very much for your replies. Now I have some idea about your discussion.
-Kokila.