Is there a preset library to
convert from double to string and
convert from string to double
You would use sprintf to convert from a number to a string and any of the ato... or strto... functions to convert from string to number.
could you give me sample how to use sprintf(). The documentation is quite difficult for me to understand without sample.
Say, I want to convert a double number into a string.:
double myDOUBLE=123.456;
char* mySTRING=GlobalAlloc(GMEM_FIXED,64); //alocate string in memory
_strnset(mySTRING,0,1); //initilize mySTRINGto ""
int sprintf(testing,myDOUBLE%???); //I can't really understand how to format it
Here are two examples
Example 1
#include <windows.h>
#include <stdio.h>
int main(void) {
double myDOUBLE=123.456;
char* mySTRING=GlobalAlloc(GMEM_FIXED,64); //allocate string in memory
_strnset(mySTRING,0,1); //initilize mySTRINGto ""
int i;
i = sprintf(mySTRING, "%G", myDOUBLE);
printf("123.456 as a string is %s\n", mySTRING);
printf("sprintf returns: %d\n\n", i);
return 0;
}
Example 2
#include <stdio.h>
int main(void) {
double dub1 = 123.456;
char str1[10];
int i;
i = sprintf(str1, "%G", dub1);
printf("123.456 as a string is %s\n", str1);
printf("sprintf returns: %d\n\n", i);
return 0;
}
I hope this helps.
Robert Wishlaw