| "Ivan Vecerina" <ivecATmyrealboxDOTcom> wrote:
| > | >> "Ivan Vecerina" <ivecATmyrealboxDOTcom> wrote:
| >> > | >> >> Given only putchar (no sprintf, itoa, etc.) write a routine
| >> >> putlong that prints out an unsigned long in decimal. No array
| >> >> allowed.
| >> >>
| >> >> I have no idea if we can't use array to solve the problem.
| >> >
| >> > One idea is to go with something like:
| >> > unsigned long exp = 10;
| >> > while(exp<val) exp*=10;
| >> > while( exp/=10 ) putchar( '0'+(val/exp)%10 );
| >> >
| >> > Bug left in on purpose, and optimizations are possible.
| >>
| >> Which bug? I count at least two.
| >
| > shush!
Is a portability problem included in your count?
Hi Richard,
| Well, the first is that it basically gives the wrong answer sometimes.
Yes - a classic bounds problem I left for Matt to eventually find.
| The second is a namespace issue.
I am not sure what you mean by this. I assume you refer
to C name spaces, and not C++ namespace-s.
A conflict with the exp() function if using <math.h> ?