Hello
So the function below can print any int using putchar. But I can't figure out how to print floats using putchar. Any ideas on this?
Regards!
Code:void putDigit(int n){ int pow = 1; char lastChar = ' '; if (n < 0){ putchar('-'); lastChar = (char)((int)'0' + (n % 10)); n /= 10; n *= (-1); } while (pow * 10 <= n) pow *= 10; while (pow != 0){ int d = n / pow; putchar((char)((int)'0' + d)); n = n - d * pow; pow /= 10; } if (lastChar != ' '){ putchar(lastChar); } }



LinkBack URL
About LinkBacks




