Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!m.cs.uiuc.edu!carroll From: carroll@m.cs.uiuc.edu Newsgroups: comp.lang.c Subject: Re: integer to string function (itoa()) Message-ID: <4700056@m.cs.uiuc.edu> Date: 30 Jun 90 17:33:00 GMT References: <22888@boulder.Colorado.EDU> Lines: 21 Nf-ID: #R:boulder.Colorado.EDU:22888:m.cs.uiuc.edu:4700056:000:1022 Nf-From: m.cs.uiuc.edu!carroll Jun 30 12:33:00 1990 /* Written 11:15 am Jun 29, 1990 by brad@SSD.CSD.HARRIS.COM in m.cs.uiuc.edu:comp.lang.c */ >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. > >Perhaps I missed something but ... Is there some reason why: > > int i = 10; char a[3]; > sprintf( a, "%d", i ); > >is unnacceptable for your purposes? I can't speak for Mr. Bailey, but I have such code because sprintf() was inadequate. In Epoch there is a need to convert longs to several different bases (i.e., 2,8,10,16) in a general way. Rolling your own itoa() is (IMHO) actually easier than kludging with special cases and sprintf(), not to mention being more efficient (sprintf() does so ugly things in many cases to work). I don't understand why this _isn't_ in the standard library, since the inverse is available. One thing that's pissed me off in the past is that I can read binary easily (using atol()), but I can't write it with equal facility.