hi everybody. Could u plz explain what's the difference between getchar(),getch e() and getch() functions. Also explain the concept of buffer .
What's the difference between getchar(),getche() and getch() functions?
Collapse
X
-
Tags: None
-
-
-
as far as I know, a c++ compiler will recognise (most) standard c code, so the methods may exist in both.
A buffer is a (temporary) storage area that is used to keep related (and usually volatile - That is things you only need at the moment) information together. I assume you want to know what the input buffer does....
Not a lot as it turns out. The input buffer is basically an interface between an input device and the memory. Any input is basically stored in the buffer while we wait to do things with it. As an example, when a program wants to write to disk, it first accumulates data in the buffer, and then starts writing as it has large chunks (this is because write processes take a long time, and so it is more efficient to try to write a sequence, rather than a character here or there).
I'm sure a more accurate answer can be found on the 'net, but hopefully this is a start.....Comment
-
Originally posted by DeManas far as I know, a c++ compiler will recognise (most) standard c code, so the methods may exist in both.
A buffer is a (temporary) storage area that is used to keep related (and usually volatile - That is things you only need at the moment) information together. I assume you want to know what the input buffer does....
Not a lot as it turns out. The input buffer is basically an interface between an input device and the memory. Any input is basically stored in the buffer while we wait to do things with it. As an example, when a program wants to write to disk, it first accumulates data in the buffer, and then starts writing as it has large chunks (this is because write processes take a long time, and so it is more efficient to try to write a sequence, rather than a character here or there).
I'm sure a more accurate answer can be found on the 'net, but hopefully this is a start.....Comment
-
I am sorry but I am not getting the concept . Could u plz explain all the three (getchar(),getc he(),getch()) in little detail and what is buffer . DeMan said it is a temporary storage area . Does it mean that when we print sth it is stored in buffer and when we press enter key it is stored in main memory but why does it not get directly stored in main memory. One more thing explain the complete process of buffer . Also I think there are both input and output buffer . Now what is the conceptComment
-
Originally posted by supriya12345I am sorry but I am not getting the concept . Could u plz explain all the three (getchar(),getc he(),getch()) in little detail and what is buffer . DeMan said it is a temporary storage area . Does it mean that when we print sth it is stored in buffer and when we press enter key it is stored in main memory but why does it not get directly stored in main memory. One more thing explain the complete process of buffer . Also I think there are both input and output buffer . Now what is the concept
As defined by IBM: "A buffer can be formally defined as "a contiguous block of computer memory that holds more than one instance of the same data type." In C and C++, buffers are usually implemented using arrays and memory allocation routines like malloc() and new. An extremely common kind of buffer is simply an array of characters."
(Citation of above quote)
A buffer is just space or memory, that can be used (also common in reading in and out variables).
Does that help?Comment
-
Originally posted by sicariegetch and getchar are the same functions, however one is for C (getch), and the other is for C++. getch() works in C++ because C++ is a superset of C - it encompasses and expands the entire C language.
getchar() is a standard library function available through stdio.h that waits and returns a keyboard character when hit. There is another function in the standard library getc() that apparently performs the same function, however getc() may be implemented as a macro were as getchar() is always implemented as a function.
Neither getch() and getche() are part of the standard library, if implemented then normally both wait for input but getch() does not echo the input character to the screen and getche() does (that is what the e stands for).
C++ is NOT a superset of C, C existed first and the 2 languages have many similarities however it is possible to write a C program that will not compile as C++ (and vis versa) and any true superset compiler would be able to compile all code written for the sub-set.Comment
-
Originally posted by supriya12345hi everybody. Could u plz explain what's the difference between getchar(),getch e() and getch() functions. Also explain the concept of buffer .
getchar() read a char from kyborad and assign to the variable like this..
prinf("Enter a char");
char c;
c=getchar();
getche() get a char and echo that char on moniter and can get in varilbe
main()
{
getche();
}
getch() doesnt echo tht char on display.
i think u get itComment
-
Originally posted by sicarieI believe getch() is from conio.h which is not considered a "standard" C or C++ library (I think it got replaced a while back). This means that if you include it in your program, you won't be able to run that program on all computers. (Personally I think using it is bad practice - especially for beginners who should be learning the foundations, not the oddities - though I realize there are people for whom it probably find it useful. I just can't think of any.)
main()
{
char c;
prinf("Enter a char");
scanf("%c",&c);
or use this statment
c=getchar();
printf("%c",c);
getch();
getche();
}Comment
-
Originally posted by BanfaC++ is NOT a superset of C, C existed first and the 2 languages have many similarities however it is possible to write a C program that will not compile as C++ (and vis versa) and any true superset compiler would be able to compile all code written for the sub-set.Comment
-
Thanks everybody . It was very nice interacting with u all. Yeah, I got it. Sicarie ur article was really interesting! Banfa u just cleared all the doubts.Comment
Comment