From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: char to int Date: Sat, 01 Mar 1997 22:15:41 -0800 Organization: Two pounds of chaos and a pinch of salt Lines: 25 Message-ID: <33191B0D.4025@cs.com> References: Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp206.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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...| ---------------------------------------------------------------------