which one is better?
Neither is better all the time. Pick the one that suits your code and needs at the time. Don't be afraid to experiment and find out for yourself.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
...checking for getch()?
Code:a = getch(); if (a == 40) do something else if...
Yoshi
getch();
One of my favorites...until <conio.h> went down the dilly with the onset of the new Standard.
Scrap it. Besides, you're only going to get one character. And, it isn't portable. Unix systems, for one, don't even handle it.
Your code is going to go down the dilly, as well. Nifty for one 'char' entries, but don't expect it to work for your example. You'll catch the '4', but...the '0' will be left in the stream and you'll have to deal with that.
Hammer, as usual, is correct. (Not being a pain, but they're "switch" statements. "Cases" are the elements of a "switch" statement.)
Personally, I hate extended IF's and IF...ELSE code. Switch statements seem so much cleaner. On the flip side, they don't always do the job since the case elements only take "integral" values. Again, as Hammer suggests, pick one that suits your needs.
-Skipper
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow
>>Unix systems, for one, don't even handle it.
Some do under the Curses libraries or there's a custom version that vVv supplied on the FAQ board. But this is going OT, so I'll stop there
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
And, I'll stand corrected.
-Skipper
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow
>> And, I'll stand corrected.
Well, yes and no. It is still non-standard. Therefore you should try and not use it.
So what is the standard function that does the same as getch()?
Somebody told me once that there is getchar() is that the one?
none...
There isn't one. getchar() is similar, but not at all the same.Originally posted by ammar
So what is the standard function that does the same as getch()?
Somebody told me once that there is getchar() is that the one?
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Thanks alot, I'll try searching the web for getchar() to know what's the difference, between it and getch().Originally posted by Hammer
There isn't one. getchar() is similar, but not at all the same.
none...
i like cases (yes i know but this one liner should be accepted).