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

CString problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
9 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.
  • A Offline
    A Offline
    andyg 101
    wrote on last edited by
    #1

    Hi there, now I have a problem with my buffer. I have a buffer reading in data from the serial port data is passed into the buffer like this

    m_serialbuffer += ch; //where m_etc is a CString and ch is a string read from the serial buffer

    Now this works perfectly for the first string that is sent to the port and stores it. For subsequent strings though, no characters are added. Any ideas?? andy

    J D 2 Replies Last reply
    0
    • A andyg 101

      Hi there, now I have a problem with my buffer. I have a buffer reading in data from the serial port data is passed into the buffer like this

      m_serialbuffer += ch; //where m_etc is a CString and ch is a string read from the serial buffer

      Now this works perfectly for the first string that is sent to the port and stores it. For subsequent strings though, no characters are added. Any ideas?? andy

      J Offline
      J Offline
      John M Drescher
      wrote on last edited by
      #2

      Is there a chance for the NULL character '\0'? CStrings are NULL terminated. John

      A 1 Reply Last reply
      0
      • J John M Drescher

        Is there a chance for the NULL character '\0'? CStrings are NULL terminated. John

        A Offline
        A Offline
        andyg 101
        wrote on last edited by
        #3

        what do you mean?

        J 1 Reply Last reply
        0
        • A andyg 101

          what do you mean?

          J Offline
          J Offline
          John M Drescher
          wrote on last edited by
          #4

          If there is a zero (ASCII 0 not the number 0) in the input the CString will not add any more characters. John

          A 1 Reply Last reply
          0
          • J John M Drescher

            If there is a zero (ASCII 0 not the number 0) in the input the CString will not add any more characters. John

            A Offline
            A Offline
            andyg 101
            wrote on last edited by
            #5

            hmm yes I think there is a zero on the end of the first string. How can I get around this?

            J D 2 Replies Last reply
            0
            • A andyg 101

              hmm yes I think there is a zero on the end of the first string. How can I get around this?

              J Offline
              J Offline
              John M Drescher
              wrote on last edited by
              #6

              Either strip the 0 with an if statement or use an array like CArray or vector. John

              A 1 Reply Last reply
              0
              • J John M Drescher

                Either strip the 0 with an if statement or use an array like CArray or vector. John

                A Offline
                A Offline
                andyg 101
                wrote on last edited by
                #7

                Nice one many thanks Andy

                1 Reply Last reply
                0
                • A andyg 101

                  hmm yes I think there is a zero on the end of the first string. How can I get around this?

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  Appending 0-terminated strings to a CString object is expected. char *name = "David"; // there is an implied \0 at the end of this string CString str = "My name is "; str += name;

                  1 Reply Last reply
                  0
                  • A andyg 101

                    Hi there, now I have a problem with my buffer. I have a buffer reading in data from the serial port data is passed into the buffer like this

                    m_serialbuffer += ch; //where m_etc is a CString and ch is a string read from the serial buffer

                    Now this works perfectly for the first string that is sent to the port and stores it. For subsequent strings though, no characters are added. Any ideas?? andy

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    The comment in this code snippet appears to be outdated. Have you stepped into the code to verify that 'ch' has valid data at the time of appending? When you state that "ch is a string", does that mean it is a string object, or are you using string in the generic sense (e.g., char ch[32])?

                    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