I\'m new to C and learning out of a book / off the internet. I\'m trying to write a function that I can pass any double
to and get returned an int
The first thing I notice is that you're dividing temp
by 10
and that is causing a loss of precision.
Not to shut you down or discourage you from trying again, but a correct implementation of this is considerably more involved than what you've shown.
Guy L. Steele and Jon L. White wrote a paper called "How to print floating-point numbers accurately" that details some of the pitfalls and presents a working algorithm for printing floating-point numbers. It's a good read.