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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. convert finction for 'unsigned char' to 'char *'

convert finction for 'unsigned char' to 'char *'

Scheduled Pinned Locked Moved C / C++ / MFC
7 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.
  • W Offline
    W Offline
    With_problem
    wrote on last edited by
    #1

    Is there any function whcih will convert 'unsigned char' to 'char *'..... Thank you:)

    S 1 Reply Last reply
    0
    • W With_problem

      Is there any function whcih will convert 'unsigned char' to 'char *'..... Thank you:)

      S Offline
      S Offline
      sunit5
      wrote on last edited by
      #2

      create a char* using new and copy the content of char into it :-D or use reinterpret_cast

      never say die

      W 1 Reply Last reply
      0
      • S sunit5

        create a char* using new and copy the content of char into it :-D or use reinterpret_cast

        never say die

        W Offline
        W Offline
        With_problem
        wrote on last edited by
        #3

        can you be more elaberote....pls i am getting error when i am using this function...... strcpy(db_TQuote.m_MarketState,marketstate); : error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char' to 'char *' Thanks...:)

        S N D 3 Replies Last reply
        0
        • W With_problem

          can you be more elaberote....pls i am getting error when i am using this function...... strcpy(db_TQuote.m_MarketState,marketstate); : error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char' to 'char *' Thanks...:)

          S Offline
          S Offline
          sunit5
          wrote on last edited by
          #4

          put the address of db_TQuote.m_MarketState

          never say die

          W 1 Reply Last reply
          0
          • W With_problem

            can you be more elaberote....pls i am getting error when i am using this function...... strcpy(db_TQuote.m_MarketState,marketstate); : error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char' to 'char *' Thanks...:)

            N Offline
            N Offline
            Nibu babu thomas
            wrote on last edited by
            #5

            abrakadbra wrote:

            strcpy(db_TQuote.m_MarketState,marketstate); : error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char' to 'char *'

            That's because the first parameter being passed to strcpy is of type unsigned char. strcpy expects a signed char* as it's first parameter. You need to cast it to char* for before passing it to strcpy. The parameter that you are passing is an unsigned char which is dangerous even if you cast it to char* since it's the target for strcpy where the copied string will be placed.


            Nibu thomas A Developer Programming tips[^]  My site[^]

            1 Reply Last reply
            0
            • S sunit5

              put the address of db_TQuote.m_MarketState

              never say die

              W Offline
              W Offline
              With_problem
              wrote on last edited by
              #6

              this is declation in my header file i am using this to store data in database...SQL server... BYTE m_MarketState;

              1 Reply Last reply
              0
              • W With_problem

                can you be more elaberote....pls i am getting error when i am using this function...... strcpy(db_TQuote.m_MarketState,marketstate); : error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char' to 'char *' Thanks...:)

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

                abrakadbra wrote:

                strcpy(db_TQuote.m_MarketState,marketstate);

                Since db_TQuote.m_MarketState is only one character, and marketstate is likely an array of characters, strcpy() is not the right tool for the job.


                "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                "Judge not by the eye but by the heart." - Native American Proverb

                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