Mail Archives: djgpp/1999/07/29/23:06:17
Darren Noble <darren AT lineo DOT com> wrote:
> ther is a funtion itoa. you sould use it like this:
>
> itoa(palette_color_r, text, 10); // 10 being the base you want the intiger to
> // be int the string
> On Wed, 27 Jan 1999, you wrote:
^^^^^ is this correct? Deja does not have this post.
> > I want to convert an integer to
> > a string. I can convert a string to an integer using atoi but there seems
> > to be no c library function to do the opposite. So it's either so simple
> > char text[3];
> > int palette_color_r;
> > text[3] = palette_color_r; // I can't cast so what?
No you can't just cast it, and in any case text[3] refers to an
element outside the bounds of that array.
Use atoi() as above or do: sprintf(text, "%d", palette_color_r);
sprintf() has the advantage of being an ANSI/POSIX function, you can
also format the number if required.
char text[3] does not allocate enough storage to cater for all
possible values of the int, even if the value is not expected to be
more than 255 this situation should probably be allowed for.
--
george
- Raw text -