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. Convert char array into CString

Convert char array into CString

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structuresquestion
7 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.
  • J Offline
    J Offline
    Johpoke
    wrote on last edited by
    #1

    I have a char array like the prevois one, ( char data[64] = "101...........) but now i need to convert all of that char array into a normal mfc CString, without the char ender ofcourse. How is this easily done? ive played with strcpy, but couldnt get it to work, thanks!!!!

    /Johannes

    M J 2 Replies Last reply
    0
    • J Johpoke

      I have a char array like the prevois one, ( char data[64] = "101...........) but now i need to convert all of that char array into a normal mfc CString, without the char ender ofcourse. How is this easily done? ive played with strcpy, but couldnt get it to work, thanks!!!!

      /Johannes

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Johpoke wrote:

      without the char ender ofcourse

      If it's a non-Unicode build you can use CString str = data; For a unicode build you can use TCHAR data[64] = "101..........."; CString str = data; For a unicode build where the string must stay a char type you can use char data[64] = "101..........."; CStringA str = data; For a unicode build where the data must stay a char type but the CString is UNICODE you can use char data[64] = "101..........."; CString str = CA2T(data);

      1 Reply Last reply
      0
      • J Johpoke

        I have a char array like the prevois one, ( char data[64] = "101...........) but now i need to convert all of that char array into a normal mfc CString, without the char ender ofcourse. How is this easily done? ive played with strcpy, but couldnt get it to work, thanks!!!!

        /Johannes

        J Offline
        J Offline
        Johpoke
        wrote on last edited by
        #3

        Thanks, its fixed, and yet another problem, with my char array, i now need to set it, but it doesnt seem to work, ie. char data[64]; data = "011111...."; [im feeding it the right amount of char any ideas? thanks

        /Johannes

        M P 2 Replies Last reply
        0
        • J Johpoke

          Thanks, its fixed, and yet another problem, with my char array, i now need to set it, but it doesnt seem to work, ie. char data[64]; data = "011111...."; [im feeding it the right amount of char any ideas? thanks

          /Johannes

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Johpoke wrote:

          im feeding it the right amount of char

          Are you saying there's 64 characters in your initialization string? If so then that's bad :) You need to have room for the NULL terminator. If you need 64 chars then define your data variable to a length of 65.

          J 1 Reply Last reply
          0
          • M Mark Salsbery

            Johpoke wrote:

            im feeding it the right amount of char

            Are you saying there's 64 characters in your initialization string? If so then that's bad :) You need to have room for the NULL terminator. If you need 64 chars then define your data variable to a length of 65.

            J Offline
            J Offline
            Johpoke
            wrote on last edited by
            #5

            yea i know about the end part the /0 or if its a \0 but i use 63 of them, 64 with that, but i just need to be able to set all of it like data = "10100010..... its probably something simple im forgetting as usual-.. thanks

            /Johannes

            M 1 Reply Last reply
            0
            • J Johpoke

              yea i know about the end part the /0 or if its a \0 but i use 63 of them, 64 with that, but i just need to be able to set all of it like data = "10100010..... its probably something simple im forgetting as usual-.. thanks

              /Johannes

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Johpoke wrote:

              its probably something simple im forgetting as usual-..

              Instead of char data[64]; data = "011111...."; try char data[64] = "011111...."; or char data[64]; strcpy(data, "011111....");

              1 Reply Last reply
              0
              • J Johpoke

                Thanks, its fixed, and yet another problem, with my char array, i now need to set it, but it doesnt seem to work, ie. char data[64]; data = "011111...."; [im feeding it the right amount of char any ideas? thanks

                /Johannes

                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #7

                Johpoke wrote:

                char data[64]; data = "011111....";

                You might like to modify it to ,

                char data[64] = {0};
                data = "011111....";

                Prasad Notifier using ATL | Operator new[],delete[][^]

                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