Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!agate!alfa.berkeley.edu!bks From: bks@alfa.berkeley.edu (Brad Sherman) Newsgroups: comp.software-eng Subject: "Program Proving" Message-ID: <1990Mar17.063012.24979@agate.berkeley.edu> Date: 17 Mar 90 06:30:12 GMT References: <52044@microsoft.UUCP> <2480006@hpcuhc.HP.COM> <1423@oravax.UUCP> <1990Mar16.210324.398@agate.berkeley.edu> <534@fwi.uva.nl> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: bks@alfa.berkeley.edu (Brad Sherman) Organization: University of California, Berkeley Lines: 46 In article <534@fwi.uva.nl> freek@fwi.uva.nl (Freek Wiedijk) writes: > [various correct criticisms] and > ...your program is _much_ too long, ... without mentioning that there is some justification for omitting the line: *s = '\0'; I still think that it would be interesting to see a proof so I'll try once more: /* --------------------------------------------------------------------- * RXUTOS * RadiX Unsigned TO String. * Converts an unsigned integer into a string of digits in any * base in the range {2, ..., 36}. Digits needed in the range * {10, ..., 35} are represented by the characters {A, B, ..., Z}. * * This function returns a pointer to a static buffer which is * on each call. On error (radix out of range), a NULL * pointer is returned. * * Author: Bradley K. Sherman (bks@alfa.berkeley.edu) * With thanks to: Freek Wiedijk (freek@fwi.uva.nl) * Copyright (C), The Regents of the University of California, 1990 */ char * rxutos( n, radix ) register unsigned int n; register unsigned int radix; { static char buf[ ( 8 * sizeof(unsigned int) ) + 1 ]; char *s = ( 8 * sizeof(unsigned int) ) + buf; if ( radix < 2 || radix > 36 ) return( 0 ); *s = '\0'; do { --s; *s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[n % radix]; n /= radix; } while ( n > 0 ); return( s ); } /* --------------------- End of file rxutos.c --------------------- */