Decimal to ASCII

Post Reply
Message
Author
phrost

Decimal to ASCII

#1 Post by phrost »

hi leute!

kann mir vielleicht irgendjemand sagen wie ich eine dezimalzahl wie z.B. 234 in das ASCII format konvertieren kann? kleiner c source code wäre super! danke im voraus

Jochen

Re: Decimal to ASCII

#2 Post by Jochen »

Da gibt's nicht viel zu konvertieren, wenn ich Dich nicht völlig falsch verstehe...

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
void main (void)
{
char c;
int i = 234;

c = (char)i;

printf ("%c\<!--no-->n",c);
exit (0);
}
</font><hr></pre></blockquote>

Ungefähr so? Das Casten ((char)i) dürftest Du Dir im allgemeinen sogar sparen können... Also nix mit gross konvertieren. Bei EBCDIC sähe das schon anders aus... <img src="http://www.pl-forum.de/UltraBoard/Images/Happy.gif" border="0" align="middle">

Jochen

Boron

Re: Decimal to ASCII

#3 Post by Boron »

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
void myItoa(int value, char* string, char stringWidth)
{
for (int k=stringWidth-1; k>=1; k--)
{
string[k] = abs(value % 10);
value /= 10;
}
}
</font><hr></pre></blockquote>

Oder so (kann sein, dass string-Übergabe nicht ganz stimmt).

Post Reply