integer to string function (itoa())

Dan KoGai dankg at headcrash.Berkeley.EDU
Sat Jul 14 18:47:34 AEST 1990


In article <64736 at lll-winken.LLNL.GOV>,
loren at tristan.UUCP (Loren Petrich) said:
>In article <22888 at boulder.Colorado.EDU> baileyc at tramp.Colorado.EDU (BAILEY CHRISTOPHER R) writes:
>>
>>Help, I need an itoa() function for use with my Sun compiler.  It seems
>>as if only PC versions of C have itoa functions.  So, source code for
>>an integer to string function would be very helpful.  Thanks!
>
>	Use the "sprintf" function -- it is like "printf" or
>"fprintf", but it takes the output string as an argument. Check your
>system's manual pages for more details.

	Well, I could speculate several reasons that itoa() is worth
coded...

1.	It's mucsimpler and faster:  itoa(buffer, 123) is niftier
	than sprintf(buffer, "%d", 123)
2.	Return value.  sprintf() returns number of chars written according
	to ANSI specs.  And itoa() returns ptr to the string written
	for most of the implementations posted here, including my own
	version (or itoa() might need only one argument if it has
	static buffer inside of it).

	It would be definitely useful if you want to code (fs)printf()
by yourself.  Wierd thing is that atoi() exists for scanf but itoa()
doesn't seem to exist in C standard library.  Does anyone know why?

----------------
____  __  __    + Dan The "I want official version of itoa(), too!" Man
    ||__||__|   + E-mail:       dankg at ocf.berkeley.edu
____| ______    + Voice:        +1 415-549-6111
|     |__|__|   + USnail:       1730 Laloma Berkeley, CA 94709 U.S.A
|___  |__|__|   + Oxymora:    Usable MS-DOS, Multitasking Mac, Secure Unix,
    |____|____  + 		rec.humor posters without sense of humor,
  \_|    |      +		Christian Science, and English grammer



More information about the Comp.lang.c mailing list