Please help me with this situation..
What is the meaning of this test:
if (!getch()==0x00) getch();
Please help me with this situation..
What is the meaning of this test:
if (!getch()==0x00) getch();
if getch() returns something besides 0 then call getch() again.
If you understand what you're doing, you're not learning anything.
Hello,
In addition to itsme86's explanation, getch() works by halting the application until the user enters a keystroke. getch() then returns the ASCII value of the keystroke as an int. System-wide keystrokes are processed by the operating system before they are returned by getch().
When getch() receives one of these keystrokes, it returns 0 to the calling program. The subsequent call to getch() returns a value for the key. Entering the following keystrokes will also cause getch() to return 0 to the calling program and return the key value on the subsequent call to getch(). For special keys, the getch function first returns ASCII 0.
0x00 is the hexadecimal value of 0.
Additional Documentation: BGI; getch()
- Stack Overflow
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
Thank you very much!
When can i use this test or for what is useful ?
if getch()==0x00) getch();
You can't. There's a syntax error in that code.
If you understand what you're doing, you're not learning anything.
i mean if (getch()==0x00) getch();
sorry for my mistake..please answer me..
thank's in advance...
try the code:
and hit an arrow keyCode:int a = getch(); int b = getch(); printf("a = %d, b = %d\n", a, b);
(lol... i need to try that out myself - i just remember it was that way in qbasic )
[edit]
if tried it now.
when you hit an arrow key the first getch() will return 224.
in case you hit Fx (F1, F2,...) the first getch() will return 0!!!
edit2: lol... i typed error key instead of arrow key - i guess i must be tired
[/edit]
Last edited by Raven Arkadon; 02-27-2005 at 05:12 PM.
signature under construction
The statement itself is pretty stupid. Break it down into words:
if getch returns a value, which, when ! is applied, is zero...Code:if( !getch() == 0x00 )
If a value is zero, applying ! to it makes it not zero. Otherwise, if the value is not zero, applying ! to it makes it zero. So why don't you just have:
However, this doesn't test for extended keys according to Borland. To test for extended keys, it should be:Code:if( getch() )
Because otherwise you're saying: "if getch returns anything other than zero...". Which doesn't test for extended keys at all.Code:if( getch() == 0 )
However...
This could be getch under curses. In which case, it returns ERR on error, or an integer value corresponding to a KEY_ value. If so, it's still a stupid statement, because they should be testing for ERR.
Quzah.
Hope is the first step on the road to disappointment.
qq: Is getch() just a shortened version of getchar()?
edit: i realised i could just find out myself... no it isn't
Last edited by ytrewq; 02-28-2005 at 01:38 PM.