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. converting TCHAR to CString giving some garbage value

converting TCHAR to CString giving some garbage value

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 Posts 6 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.
  • V Offline
    V Offline
    VCProgrammer
    wrote on last edited by
    #1

    Hi all, I have made a application in vc2008, I have made a TCHAR variable...

    TCHAR prdcode[10];

    My problem is i want to assign this value to CString variable...

    CString test = prdcode;

    but while assigning value it takes some garbage value.... how can i do it... thanks in advance

    C _ C D 4 Replies Last reply
    0
    • V VCProgrammer

      Hi all, I have made a application in vc2008, I have made a TCHAR variable...

      TCHAR prdcode[10];

      My problem is i want to assign this value to CString variable...

      CString test = prdcode;

      but while assigning value it takes some garbage value.... how can i do it... thanks in advance

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      VCProgrammer wrote:

      but while assigning value it takes some garbage value....

      How do you check that ? In oyur code snippet, you didn't assign anything to prdcode, so it will contain garbage at that time. Show use the code where you write something in it.

      Cédric Moonen Software developer
      Charting control [v1.5] OpenGL game tutorial in C++

      V 1 Reply Last reply
      0
      • V VCProgrammer

        Hi all, I have made a application in vc2008, I have made a TCHAR variable...

        TCHAR prdcode[10];

        My problem is i want to assign this value to CString variable...

        CString test = prdcode;

        but while assigning value it takes some garbage value.... how can i do it... thanks in advance

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

        TCHAR prdcode[10] = _T("thisvalue");
        CString test = prdcode;

        «_Superman_»

        V 1 Reply Last reply
        0
        • _ _Superman_

          TCHAR prdcode[10] = _T("thisvalue");
          CString test = prdcode;

          «_Superman_»

          V Offline
          V Offline
          VC Maniac
          wrote on last edited by
          #4

          Either use _tcscpy() for initializing prdcode or put the string directly to the CString object.

          1 Reply Last reply
          0
          • C Cedric Moonen

            VCProgrammer wrote:

            but while assigning value it takes some garbage value....

            How do you check that ? In oyur code snippet, you didn't assign anything to prdcode, so it will contain garbage at that time. Show use the code where you write something in it.

            Cédric Moonen Software developer
            Charting control [v1.5] OpenGL game tutorial in C++

            V Offline
            V Offline
            VCProgrammer
            wrote on last edited by
            #5

            my prcode is getting a value.... and i am assigning that value to my CString variable.... suppose it has 10 characters starting will be ok but at end it'll show garbage value....

            C 1 Reply Last reply
            0
            • V VCProgrammer

              my prcode is getting a value.... and i am assigning that value to my CString variable.... suppose it has 10 characters starting will be ok but at end it'll show garbage value....

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #6

              VCProgrammer wrote:

              my prcode is getting a value....

              Well, where is your code ? Without code, it's difficult to help...

              VCProgrammer wrote:

              starting will be ok but at end it'll show garbage value....

              Did you forget the zero termination of the string ?

              Cédric Moonen Software developer
              Charting control [v1.5] OpenGL game tutorial in C++

              1 Reply Last reply
              0
              • V VCProgrammer

                Hi all, I have made a application in vc2008, I have made a TCHAR variable...

                TCHAR prdcode[10];

                My problem is i want to assign this value to CString variable...

                CString test = prdcode;

                but while assigning value it takes some garbage value.... how can i do it... thanks in advance

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

                Well, possibly prdcode contains garbage, you didn't show us how did you fill the array content... :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
                • V VCProgrammer

                  Hi all, I have made a application in vc2008, I have made a TCHAR variable...

                  TCHAR prdcode[10];

                  My problem is i want to assign this value to CString variable...

                  CString test = prdcode;

                  but while assigning value it takes some garbage value.... how can i do it... thanks in advance

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

                  VCProgrammer wrote:

                  ...it takes some garbage value....

                  How are you verifying this?

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  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