6
I recently took a test and there was a question that asked for a number like 123.456 was shown as 321.456. I thought the best solution would be to convert this to an array of char and then create an algorithm to print position by position, using pointers, with the . and the \0 served as stop tokens. I implemented the algorithm but don’t know how to make this one float to an array of char so that each digit is in one position.
How do I convert a float in an array of char in C/C++?
I was also curious to know how to do this with other guys. int for char, byte for char and do the opposite process as well (char for float).
Excellent answer. Could you tell me how the implementation of the sprintf function is done? I tried to find it on the internet but did not find.
– Avelino
The implementation is quite large. You can see the gcc version if you download the
glibcand search instdio-common. Research on lexical analysis also has to do with.– Lucas Lima
No need to explicitly pass the template argument to the
to_string(last example).– Guilherme Bernal