How to convert Float array to char
-
I would like to write values to a file, and now the member of Class A is const valueType *getValues(int start) const { evaluate(); return (const valueType *)(values + start); } I tried to use CString/_gcvt to convert it to string/charm=, but failed. Anyone can help me how to realize it? thanks
-
I would like to write values to a file, and now the member of Class A is const valueType *getValues(int start) const { evaluate(); return (const valueType *)(values + start); } I tried to use CString/_gcvt to convert it to string/charm=, but failed. Anyone can help me how to realize it? thanks
Hi, I think sprintf will do the trick for your Question. I didnt try it. #include #include char *DoubletoStr(char *s, double dd); int main(void) { double values2[] = {34709.22, 3746.55, 23456}; char value[32]; int i; DoubletoStr(value,values2[i])); return 0; } char *DoubletoStr(char *s, double dd) { char *endp; sprintf(s,"%f",dd); for(endp = s+strlen(s); endp!=s;endp--) { if(*(endp-1) != '0'&& *(endp-1) != '.') { *endp = '\0'; break; } } return s; } Good Luck. Helping others satisfies you...
-
I would like to write values to a file, and now the member of Class A is const valueType *getValues(int start) const { evaluate(); return (const valueType *)(values + start); } I tried to use CString/_gcvt to convert it to string/charm=, but failed. Anyone can help me how to realize it? thanks
not sure I understood the problem. if you have an array and you want to simply DUMP it to a file, you don't need to do any convertions. the data (in the memory) is already stored in bytes (and bytes are the same, memory wise, as chars). just use the sizeof(float) * the number of elements, and cast that array to a char* variable. If you want to convert the data to a text data, you'll need to format it. either use CString, of sprintf Hope this helps.