hi everybody. Could u plz explain what's the difference between getchar(),getch e() and getch() functions. Also explain the concept of buffer .
16 23363 DeMan 1,806
Top Contributor
getchar will wait till return is pressed
getche will see the characters as they're type.
getch (i think) is the same as getchar but one is for c the other for c++
Thanks Deman but could u plz explain in a little detail n also tell about buffer
one more thing I don't know C . and all these functions are there in C++
DeMan 1,806
Top Contributor
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.....
sicarie 4,677
Recognized Expert Moderator Specialist
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.....
I 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.)
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 concept
sicarie 4,677
Recognized Expert Moderator Specialist
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 concept
getch 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. However, conio.h (the library that getch() is in), is not a "standard" C library, and is not included with all compilers. Having ranted enough about getch(), the difference between getchar() and getche() is that one will read from input (getche()), the other will wait until the return key is pressed (getchar()).
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?
Banfa 9,065
Recognized Expert Moderator Expert
getch 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.
Sorry this just isn't right.
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.
hi everybody. Could u plz explain what's the difference between getchar(),getch e() and getch() functions. Also explain the concept of buffer .
hi supriya.
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 it
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Emmanuel Delahaye |
last post by:
Hi there,
It is commonly accepted that a call to the getchar() function suspends the
execution of the current program. I have not found any description of this
behaviour in the standard (I may have missed it).
I was wondering wether it was just a 'common' behaviour of most systems, and
wether the hit of the ENTER key was mandatory.
Thanks for having read me.
|
by: Justine |
last post by:
Hi All,
Which is function equivalent to getch/getche of C++.
Thanz in Advance,
Justine
|
by: srikanth |
last post by:
help me out with the subject
|
by: vicky |
last post by:
why is the output of the following command is 4 4 5.
main()
{
int a=2;
printf("%d",printf("\n%d %d",a,a,a);
getch();
}
i did not understand what these two printf in a command signifies.
|
by: Daniel.C |
last post by:
Hello.
I just copied this code from my book with no modification :
#include <stdio.h>
/* count characters in input; 1st version */
main()
{
long nc;
nc = 0;
| |
by: shakeel225 |
last post by:
Hi!
I am shakeel ahmad and want to know how are the above mentioned functions used particularly in linux as I am always finding a difficulty in using these functions.......
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |