Mostly, I can get this to work, but I am stuck trying to figure out how to handle the printing of floating point value (eg. printf("%f", floatnum);)
I have done this:
Code: Select all
fnum = va_arg(arglist, double);
printf("%d", (int)fnum); /* Print the integer part, truncate the fraction */
putchar('.'); /* Decimal point */
if(fnum<0) /* If negative, remove the sign */
fnum = -fnum;
fnum = (fnum - (int)fnum) * 1000000; /* Get numbers after decimal point */
printf("%d", (int)fnum);
I thought that I may be able to get the double and break it into it's compenents (sign, exponent and mantissa), but I don't think I can get the bits out of a double.
I don't want someone to do the work for me, but I do need a point in the right direction.
Thanks for your help.