Path: utzoo!attcan!uunet!samsung!emory!ogicse!plains!bakke From: bakke@plains.UUCP (Jeffrey P. Bakke) Newsgroups: comp.lang.c Subject: Re: integer to string function (itoa()) Message-ID: <5194@plains.UUCP> Date: 1 Jul 90 12:58:56 GMT References: <22888@boulder.Colorado.EDU> <4700055@m.cs.uiuc.edu> Organization: North Dakota State University, Fargo Lines: 66 In article <4700055@m.cs.uiuc.edu> carroll@m.cs.uiuc.edu writes: > > I got a number of requests for this, so here it is: > (This code is taken out of Epoch, where it works just fine). > .... CODE > > Alan M. Carroll Barbara/Marilyn in '92 : > carroll@cs.uiuc.edu + This time, why not choose the better halves? > Epoch Development Team > CS Grad / U of Ill @ Urbana ...{ucbvax,pur-ee,convex}!cs.uiuc.edu!carroll I'm not sure if I'm jumping in on the middle of a discussion but I happened to catch this post as I went by. An alternate to this code is the code implemented directly in K&R. If the above code is part of a discussion of alternate methods of the itoa function than K&Rs, ignore the following code. /* -------------------------------------- Name: IntString Function: Converts a Long integer value to a string Call: IntString(n,str); Returns: void -------------------------------------- */ void IntString(n,str) long n; char *str; { int i=0; long int sign; if ((sign = n) < 0) n =- n; do str[i++] = (n % 10) + '0'; while (( n /= 10) > 0); if (sign < 0) str[i++] = '-'; str[i] = '\0'; Reverse(str); } /* -------------------------------------- Name: Reverse Function: Reverse string Call: Reverse(str); Returns: void -------------------------------------- */ void Reverse(str) char *str; { int i,j; char c; for (i=0,j=(strlen(str)-1);i