Re: Converting from and INT back to ASCII character

From: ian (ib252_at_n0spam.com)
Date: 10/09/03


Date: Wed, 8 Oct 2003 18:31:44 -0400

Hello Dave,

to convert integer to ASCII string:
    #include <stdio.h>

    char szBuf[50];
    int i = 123;
    sprintf (szBuf, "%i", i);

to convert ASCII string to integer
    #include <stdio.h>
    #include <stdlib.h>

    char szBuf[50] = "123";
    int i;
    sscanf (szBuf, "%i", &i); // method #1
    i = atoi (szBuf); // method #2

to convert an ASCII character to an integer
    char cCh = 'A';
    int i = static_cast<int>(cCh);

to convert an integer to an ASCII character
    int i = 65;
    char cCh = static_cast<char>( i); // cCh is set to 'A'

"David Williams" <dswilliams@dsl.pipex.com> wrote in message
news:3f84773c$0$6631$cc9e4d1f@news.dial.pipex.com...
> Hi all, i have been able to convert an ASCII character to an INT however
im
> lost as to how to change them back. Cant find anything on the net (though
im
> probably looking in the wrong places!). Could anyone help me out?
>
> Thanks
> Dave
>
>



Relevant Pages

  • Re: Why is Java so slow????
    ... The buffer must be therefore at least the size of Integer.MAX_VALUE + ... buff.start stores the offset of the first ASCII character. ... static void fastItoS2(AsciiByteBuff buff, int i) { ... public int slength; ...
    (comp.lang.java.programmer)
  • Re: int to ascii character?
    ... >I know it must be something simple but I cant find out! ... Dos anyone know how ... >to convert an int to its corresponding ascii character? ...
    (microsoft.public.windowsce.embedded.vc)
  • Is it normal : wide string and cout works strange ???
    ... I'm a bit in trouble because I can't print wstring when there is a non ... ASCII character inside: ... int main ...
    (comp.lang.cpp)
  • Re: Converting from and INT back to ASCII character
    ... i have been able to convert an ASCII character to an INT however ... > lost as to how to change them back. ... Cant find anything on the net (though ...
    (comp.lang.cpp)
  • Re: Converting from and INT back to ASCII character
    ... i have been able to convert an ASCII character to an INT however ... > lost as to how to change them back. ... Cant find anything on the net (though ...
    (comp.lang.cpp)