delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/01/23:28:18

Date: Sat, 1 Mar 1997 23:20:41 -0500 (EST)
From: Michael Phelps <morphine AT hops DOT cs DOT jhu DOT edu>
To: rellwood <rellwood AT aludra DOT usc DOT edu>
cc: djgpp AT delorie DOT com
Subject: Re: char to int
In-Reply-To: <Pine.SV4.3.94.970301143114.733A-100000@aludra.usc.edu>
Message-ID: <Pine.GSO.3.95.970301231520.10846B-100000@hops.cs.jhu.edu>
MIME-Version: 1.0

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



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019