Posted by James Durbin on 1999-04-21
> index = 0; > while (number != 0) do > string[index++] = number MOD 10 + 48; > number = number / 10; > od > reverse string; I would have used a for loop to create a fixed length string with leading 0's or with leasing spaces that way you don't have to reverse the string if you use a backwards counting counter (index--) and starting with the highest possible chars in the string... and I would also put in a '0' insted of 48 just for readability purposes...(it makes more sence to me to add 'zero' to the number than it does to add 48) but then which one you use depends on what it's used for... -- /* From: James H. Durbin Email: divine-bovine@xxxx.xxx */
Previous post | Next post | Timeline | Home