#Convert double to char array/string
20 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
union data
{
char tmp[8];
double d_var;
};
int main(){
data obj;
obj.d_var ==1;
for(int x=0; x<8;x++)
printf("%c", obj.tmp[x]);
}
thank you, and how do i use that?
@wild dawn Has your question been resolved? If so, run !solved :)
example
thank you
i'm trying to understand it: is it one piece of data that is either read as char or as double ? is that correct?
Patreon ► https://patreon.com/thecherno
Twitter ► https://twitter.com/thecherno
Instagram ► https://instagram.com/thecherno
Discord ► https://thecherno.com/discord
Series Playlist ► https://thecherno.com/cpp
Thank you to the following Patreon supporters:
- Dominic Pace
- Kevin Gregory Agwaze
- Sébastien Bervoets
- Tobias Humig
- Peter Siegmund...
That's C++ but we're in the C channel
mmmh
that is the output
shall we reconstruct the question?
do you really need to convert the double value to char array/char *?
OR
do you just want to print out the number?
sprintf()/snprintf() for
do you really need to convert the double value to char array/char *?
printf() for
do you just want to print out the number?
i want to print the number on an OLED display on a nucleo64.
the given library provides a function that expects a string/char array. the library is c++ btw. it’s a bit confusing.
it is mainly C
and converting a double to an int is not specific to embedded devices. it is C
not really. it depends on what libraries the embedded compiler have.
It may not have stdio or stdlib since those libraries may be too big for the system.
and I already given the answer (how you do it with std C library)
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.