hi there)
my brothers-programmers) please tell me - how to get double type character by character - i need make custom realization of fprintf - so it's necessary for me to show double type numder on the screen.
(For integer type this problem could be solved by subtracting 32 - and after that putchar() can be used.)
big thanks in advance)
Use sprintf(string,"%f",variable) to print it to a string then you can do what you want with it.
See the Pelles C help file for more details...
I can use only language kernel - e.g. only putchar for the screen (without libraries)))
Quote from: vedro-compota on May 02, 2012, 08:31:02 PM
I can use only language kernel - e.g. only putchar for the screen (without libraries)))
Maybe you should explain a bit more in detail what you are trying to do, so we understand what possible constraints you have (due to homework/course assignment?)...
Ralf
yes - it's something like homework - i need to realize the fprintf() - the base function for this - as i understand is putchar() -
putchar() is enough for string type =
%s
and, as i think for int to
%i
Quote from: vedro-compota on May 02, 2012, 08:49:55 PM
yes - it's something like homework - i need to realize the fprintf() - the base function for this - as i understand is putchar() -
putchar() is enough for string type =
%s
and, as i think for int to
%i
Well, as a general rule (which I am sure you have been told already), we do not do any homework for you... ;)
Beside that, doing it generally for floats isn't that much different that doing it for integers. You just have to to separate the whole number part from the fraction and run a loop for each of the digits to be output, with possible padding in front of the whole number part and filling with zeros possibly on the fraction part, up to a defined precision...
Ralf
Quote>>>>we do not do any homework for you...
i didn't asked you for this)
yes - I needed something like this idea)thank you )
but this -
Quote>>>>padding in front of the whole number part
I can't understand - could you give example (not code - just float number)
Take a look to http://www.koders.com/ (http://www.koders.com/) to have a look to printf or sprintf subroutines.
thanks for advice, frankie)
there's a source code here (http://www.codeforge.com/article/67047), but the solution is quite massive...
I think that this http://www.koders.com/c/fid8684644B8325F0D91A103EA7750A9269E1F99856.aspx?s=ftoa#L651 (http://www.koders.com/c/fid8684644B8325F0D91A103EA7750A9269E1F99856.aspx?s=ftoa#L651) is enough for you (the only ftoa function).