[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: not enough real programmers? (was Re: Byte Magazine: 18 Vintage issues, 1985-1986)



fungus <fungus@egg.chips.and.spam.com> wrote:

>
>
>Gene Wirchenko wrote:
>> 
>> 
>> >3.  "Write a function to print out a 32-bit number in decimal, but in
>> >reverse."
>> 
>>      I like this one.  Again, there are platform considerations.
>> 
>
>Not really, just use unsigned longs.

     I believe it would be a conforming implementation of C to have
short, int, and long all be 16 bits. In that case, using unsigned long
wouldn't be enough.

>Anyway, in reverse order is the easy case. Printing the number
>in forward order requires a lot more twiddling.

     Start filling the string at the far end of a space wide enough to
hold the longest possible value.  Decrement the pointer as you
generate the digits and return the pointer pointing to the first
character.

>(Assuming we're not using the standard library here...)

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
     I have preferences.
     You have biases.
     He/She has prejudices.