Mail Archives: djgpp/1997/03/01/23:11:55
rellwood wrote:
>
> Is there a function I can use to convert a char to an int? The closest
> thing I can find is atoi(), which actually converts a string. Is there
> anything better?
I'm not sure what you mean. If you want an individual character, then
why not just use (c - '0'), as in the following:
int getdigit( void )
{
int c;
printf( "Type a digit: " );
fflush( stdout );
while ( ( c = getchar( ) ) < '0' || c > '9' )
printf( "Please type a digit.\n" );
return c - '0';
}
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | fighteer AT cs DOT com |
| Descent 2: The Infinite Abyss - The greatest Internet game of all |
| time just got better! This time, you're going all the way down...|
---------------------------------------------------------------------
- Raw text -