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. copy CString value to char

copy CString value to char

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
4 Posts 4 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.
  • A Offline
    A Offline
    Anu_Bala
    wrote on last edited by
    #1

    HI, i cannot copy CString value to char.but it show error.I typecast the CString value ,but still i get errors. Pls help me out. char cAlarmStatus; CString AlCond; if(...) AlCond = "HH"; else AlCond = "LL"; strcpy(objAlarmData->cAlarmStatus,(LPCTSTR)AlCond); I get error that cannot convert parameter one form char to char*. Pls help me how to copy this CString AlCond to cAlarmStatus

    Anu

    M C 2 Replies Last reply
    0
    • A Anu_Bala

      HI, i cannot copy CString value to char.but it show error.I typecast the CString value ,but still i get errors. Pls help me out. char cAlarmStatus; CString AlCond; if(...) AlCond = "HH"; else AlCond = "LL"; strcpy(objAlarmData->cAlarmStatus,(LPCTSTR)AlCond); I get error that cannot convert parameter one form char to char*. Pls help me how to copy this CString AlCond to cAlarmStatus

      Anu

      M Offline
      M Offline
      Maxwell Chen
      wrote on last edited by
      #2

      char T[100] = {0};
      CString S = "Hello";
      strcpy(T, S.GetString());

      Maxwell Chen

      P 1 Reply Last reply
      0
      • M Maxwell Chen

        char T[100] = {0};
        CString S = "Hello";
        strcpy(T, S.GetString());

        Maxwell Chen

        P Offline
        P Offline
        Parthi_Appu
        wrote on last edited by
        #3

        To add with Maxwell's answer, In your code you used 'char' and not 'char*'.. Try using as Maxwell said or you can allocate memory at runtime with the lenght of CString object and copy the string (but don't forget to release/delete the memory allocated)


        Do your Duty and Don't expect the Result

        1 Reply Last reply
        0
        • A Anu_Bala

          HI, i cannot copy CString value to char.but it show error.I typecast the CString value ,but still i get errors. Pls help me out. char cAlarmStatus; CString AlCond; if(...) AlCond = "HH"; else AlCond = "LL"; strcpy(objAlarmData->cAlarmStatus,(LPCTSTR)AlCond); I get error that cannot convert parameter one form char to char*. Pls help me how to copy this CString AlCond to cAlarmStatus

          Anu

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          What do you really need? I mean, you cannot usually copy the whole CString content to a char variable (it can hold a single character), you need a character array or a pointer to dynamic allocated memory. On the other hand, you probably don't need at a CString object:

          const char * pszAlarmStatus;
          if(...)
          pszAlarmStatus = "HH";
          else
          pszAlarmStatus = "LL";

          that's all. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          [my articles]

          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