I'm working on a code to create my own printf. The use of printf, sprintf, and the like are prohibited. I need to convert a double type variable to a char type variable in order to use it in a puts() function with prefixes and other things added. How do I turn a double into a string?
I found this earlier, but it only converts the memory of the variable to a string:
#include <string.h>
double a=2.132;
char arr[sizeof(a)];
memcpy(arr,&a,sizeof(a));
What can I do to make this a variable? So far, the snippet of my code where I integrated that looks like this:
double num = 10.99;
char arr[sizeof(num)];
memcpy(arr, &num, sizeof(num));
puts(arr);
//Expected output: 10.99
//Actual output:
doesn't work and will return nothing to the console. If anyone could point me in the right direction, that would be much appreciated!