which one is better?:)
Printable View
which one is better?:)
Depends on what you're trying to do.
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.
...checking for getch()?
Code:a = getch();
if (a == 40)
do something
else if...
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
>>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 :)
And, I'll stand corrected. :D
-Skipper
>> 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?
There isn't one. getchar() is similar, but not at all the same.Quote:
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?
Thanks alot, I'll try searching the web for getchar() to know what's the difference, between it and getch().Quote:
Originally posted by Hammer
There isn't one. getchar() is similar, but not at all the same.
i like cases (yes i know but this one liner should be accepted).