This is a discussion on Some help for a Noobie! within the C Programming forums, part of the General Programming Boards category; Originally Posted by Elysia There are more elegant solutions... Well, none of them is offered here....
For example.Code:char c = getchar(); if (is_digit(c)) { c -= '0'; // Do whatever }
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
Last edited by Subsonics; 11-29-2009 at 07:43 AM.
I suppose the OP was, yes. So in the OP's code, it would work fine, your example. For a generic solution of getting the actual number it represents (the -48 discussion), my example is better.
And neither handles UTF properly.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
I would argue that - '0' explains it even better (how can you subtract two letters from each other?).
To the last, then what is the point of using any method at all? Nothing is perfect. Remember that well. But there are ways to make it more perfect.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
Wouldn't it be possible to make a univeral input method that recognices and handles any character encoding properly? I would think so, but I bet it's not going to be elegant. ;-)
Possible? No doubt. But messy, yes.
C++ handles these things much more smoothly.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^