Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!bionet!agate!headcrash.Berkeley.EDU!dankg From: dankg@headcrash.Berkeley.EDU (Dan KoGai) Newsgroups: comp.lang.c Subject: Re: integer to string function (itoa()) Message-ID: <1990Jul14.084734.29071@agate.berkeley.edu> Date: 14 Jul 90 08:47:34 GMT References: <22888@boulder.Colorado.EDU> <64736@lll-winken.LLNL.GOV> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: dankg@headcrash.Berkeley.EDU (Dan KoGai) Distribution: usa Organization: ucb Lines: 35 In article <64736@lll-winken.LLNL.GOV>, loren@tristan.UUCP (Loren Petrich) said: >In article <22888@boulder.Colorado.EDU> baileyc@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@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