ANSI C function for itoa ? 
Author Message
 ANSI C function for itoa ?

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?  I see
itoa in some of the documentation for my compiler (lcc-win) but it notes
portability is restricted to windows.  Also, I do not find itoa in my C
reference book.

regards,

Rory Johnson



Sat, 12 Feb 2005 09:37:59 GMT  
 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?  I
> see itoa in some of the documentation for my compiler (lcc-win) but it
> notes portability is restricted to windows.  Also, I do not find itoa
> in my C reference book.

There is not.

The normal way to do this is to do a sprintf() (or, alternatively a
snprintf()) to a buffer.

HTH,
--ag

--
Artie Gold, Austin, TX



Sat, 12 Feb 2005 09:51:03 GMT  
 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



Sat, 12 Feb 2005 14:48:44 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ansi substitution for itoa?

2. ANSI Safe itoa?

3. Why no itoa in ANSI C

4. Why no itoa in ANSI C?

5. Newbie: separate big .cs file into small .cs files

6. recursive itoa function?

7. itoa, ltoa and time functions

8. itoa function???....

9. Is there an itoa() function (opposit of atoi())????

10. itoa function caused "conflicting types" error

11. integer to string function (itoa())

12. integer to string function (itoa())

 

 
Powered by phpBB® Forum Software