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. char array to string

char array to string

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
8 Posts 5 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.
  • L Offline
    L Offline
    lune12
    wrote on last edited by
    #1

    Hi, I have a char array with 2 elemts. char c[2]; c[0] = 0x10; c[1] = 0x06; I want a string that will hold "1006". How can I do that? Thanks.

    R _ H 3 Replies Last reply
    0
    • L lune12

      Hi, I have a char array with 2 elemts. char c[2]; c[0] = 0x10; c[1] = 0x06; I want a string that will hold "1006". How can I do that? Thanks.

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      You could use _stprintf[^] or if you're using MFC, look at CString::Format()[^]

      It is a crappy thing, but it's life -^ Carlo Pallini

      1 Reply Last reply
      0
      • L lune12

        Hi, I have a char array with 2 elemts. char c[2]; c[0] = 0x10; c[1] = 0x06; I want a string that will hold "1006". How can I do that? Thanks.

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        char str[5];
        sprintf(str, "%02X%02X", char[0], char[1]);

        «_Superman_» I love work. It gives me something to do between weekends.

        modified on Wednesday, May 20, 2009 2:12 AM

        L C 2 Replies Last reply
        0
        • L lune12

          Hi, I have a char array with 2 elemts. char c[2]; c[0] = 0x10; c[1] = 0x06; I want a string that will hold "1006". How can I do that? Thanks.

          H Offline
          H Offline
          H r ld
          wrote on last edited by
          #4

          char szData[] = "1006"; or char szData[AnySizeGreater4] = "1006";

          _ 1 Reply Last reply
          0
          • H H r ld

            char szData[] = "1006"; or char szData[AnySizeGreater4] = "1006";

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            Good one. Simple and nice.

            «_Superman_» I love work. It gives me something to do between weekends.

            1 Reply Last reply
            0
            • _ _Superman_

              char str[5];
              sprintf(str, "%02X%02X", char[0], char[1]);

              «_Superman_» I love work. It gives me something to do between weekends.

              modified on Wednesday, May 20, 2009 2:12 AM

              L Offline
              L Offline
              lune12
              wrote on last edited by
              #6

              Thanks

              1 Reply Last reply
              0
              • _ _Superman_

                char str[5];
                sprintf(str, "%02X%02X", char[0], char[1]);

                «_Superman_» I love work. It gives me something to do between weekends.

                modified on Wednesday, May 20, 2009 2:12 AM

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

                I see a flaw in your code (I supposed supeheroes flawless... :rolleyes:). :)

                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.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                _ 1 Reply Last reply
                0
                • C CPallini

                  I see a flaw in your code (I supposed supeheroes flawless... :rolleyes:). :)

                  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.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  _ Offline
                  _ Offline
                  _Superman_
                  wrote on last edited by
                  #8

                  Oooops. Ahem! Actually I leave that to the compiler. :-\

                  «_Superman_» I love work. It gives me something to do between weekends.

                  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