Date: Sat, 1 Mar 1997 23:20:41 -0500 (EST) From: Michael Phelps To: rellwood cc: djgpp AT delorie DOT com Subject: Re: char to int In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On 1 Mar 1997, 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? > > -Richard > Why do you want to do this? In C and C++, a char can be automatically converted into an int. The resulting integer contains the ASCII code of the character. For instance, int sample = 'X'; /* sample == 88 on most systems */ Is this _really_ what you want to do? It's perfectly legal, and will work as advertised as long as you know what you're doing. ---Michael Phelps morphine AT cs DOT jhu DOT edu CH3 | N / | ______/ | / \ CH2 _____/ \__|__ // \\ / | \\ // \\______/___CH2 \\ \ / \ / \______/ \_____/ / ------ \ / \ OH \ / OH O Morphine