
ANSI C function for itoa ?
Quote:
> Is there an ANSI C function which, given an integer, will return a
> pointer to a string whose contents are the integer in text form?
No. Why not write one?
#include <stdio.h>
const char *int2txt(int i)
{
static char text[20] = {0};
sprintf(text, "%d", i);
return text;
Quote:
}
int main()
{
const char *p = int2txt(42);
printf("%s\n", p);
return 0;
Quote:
}
>I see
> itoa in some of the documentation for my compiler (lcc-win) but it notes
> portability is restricted to windows.
Right. There is no function 'itoa' in standard C.
Quote:
>Also, I do not find itoa in my C
> reference book.
Right. There is no function 'itoa' in standard C.
It's closest equivalent is 'sprintf()'.
-Mike