Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to convert Float array to char

How to convert Float array to char

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelptutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wjming
    wrote on last edited by
    #1

    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

    C C 2 Replies Last reply
    0
    • W wjming

      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

      C Offline
      C Offline
      chetan210183
      wrote on last edited by
      #2

      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...

      1 Reply Last reply
      0
      • W wjming

        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

        C Offline
        C Offline
        ChaosDude
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups