Question:
In Programming, Is the code getch() C or C++?. I need the C version of it for a total C assignment?
ADH
2009-11-15 09:24:22 UTC
I need to do my assignment using just C syntax and want to know if getch() is C or not. If not what is the C equivalent?
Five answers:
?
2009-11-15 10:06:56 UTC
getch is neither +ANSI/ISO+ C nor +ANSI/ISO+ C++. It is a compiler extension, which may or may not be supported by your compiler. controlled terminal input is supported by the curses library, which is coming with many unix systems. You can check this freeware port of curses - pdcurses - , which would allow for a portable approach to getch() functionality.

For windows: Borland has the getch function

Microsoft has the _getch function. None of them are ANSI, ISO. Does these mean now to not use this function? NO. But in case you are going for the solution of "C"/"C++" language this is NOT the way to go.
?
2009-11-15 14:18:17 UTC
As NickT says, getch() is in the standard C library. You can use it in either C or C++. You can use any C function in C++.



While I have no doubt MichaelInScarborough is correct, getch() has been available on almost every system I have coded with C, including Windows and various platforms using Linux/Unix.



The only exceptions to this are platforms that don't have a keyboard (games consoles).
2016-04-04 04:27:16 UTC
You are trying to compare the content of bname with the value XYZ and are getting an error when you write: if (bname == XYZ) That's because XYZ looks like the name of some data, like bname and the compiler does not know what XYZ is. In many languages you would write that as: if (bname == "XYZ") The quotes around XYZ tell the compiler it is a value not a name. However in C that still will not work, instead you have to write the following: if (strcmp(bname, "XYZ)) == 0) That uses a function called strcmp to compare the value in bname with the value XYZ, if they are the same it returns 0, which is tested for with the == 0 clause. Additionally bname need to be declared as follows: char bname[100]; That says bname has room for 100 characters (I chose 100 fairly randomly). The value XYZ is actually four characters long! "XYZ" is represented by the three letter characters X, Y and Z plus an ending character called a null.
Manoj Patel
2009-11-15 10:19:04 UTC
hi friend

getch() is a function in C language.

it gets one character as input but the key pressed by us is not visible on screen.

to use getch() in our program we need to include following header file

#include



Main purpose of getch() is to write such programs that take input from user but user is not able to view it on the monitor screen. for Example taking Password as input.. in this kind of program no one can see what we enter.
Nick T
2009-11-15 09:58:14 UTC
getch is a standard c library function.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...