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. ERROR 'strcpy' : cannot convert parameter 1 from 'TCHAR [20]' to 'char *'

ERROR 'strcpy' : cannot convert parameter 1 from 'TCHAR [20]' to 'char *'

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
20 Posts 8 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.
  • R Rajesh R Subramanian

    There is a boatload of CRT string manipulation functions. You can be kind enough not to add a query here for every single function that is referred to in your code. Just get to the documentation page[^] and click on the function that you're using. Then, choose the generic text mapping routine version (tchar.h routine) of that function. As an example, choose _tcsdec instead of _strdec. You might want to read about Using Generic Text-Mappings[^].

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

    P Offline
    P Offline
    Purish Dwivedi
    wrote on last edited by
    #11

    Code Segment is token=strtok(userid,_T(";")); What about this error? 'strtok' : cannot convert parameter 2 from 'const wchar_t [2]' to 'const char *'

    R 1 Reply Last reply
    0
    • P Purish Dwivedi

      Code Segment is token=strtok(userid,_T(";")); What about this error? 'strtok' : cannot convert parameter 2 from 'const wchar_t [2]' to 'const char *'

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

      Is it really that difficult? Read my previous reply to you again. Go to the documentation page and click on strtok and choose the generic text mapping routine equivalent instead. You need to read on Unicode, Generic Text mappings, Internationalization, and string manipulation. You really need to.

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

      P 1 Reply Last reply
      0
      • R Rajesh R Subramanian

        Is it really that difficult? Read my previous reply to you again. Go to the documentation page and click on strtok and choose the generic text mapping routine equivalent instead. You need to read on Unicode, Generic Text mappings, Internationalization, and string manipulation. You really need to.

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

        P Offline
        P Offline
        Purish Dwivedi
        wrote on last edited by
        #13

        I have changed that. Now the new error is 'wcstok' : cannot convert parameter 1 from 'char [1000]' to 'wchar_t *' what should I do now?

        R 1 Reply Last reply
        0
        • P Purish Dwivedi

          I have changed that. Now the new error is 'wcstok' : cannot convert parameter 1 from 'char [1000]' to 'wchar_t *' what should I do now?

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

          Purish Dwivedi wrote:

          what should I do now?

          You are looking for someone to give you an 'instant fix' (not to mention you post a query for every error of the same type) without even understanding your problem properly, which is essentially not going to help you in the longer run. I am wanting you to understand the basics so that you will be able to solve the problem yourself. Therefore, do what Cédric asked you to do[^]

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

          P 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            Purish Dwivedi wrote:

            what should I do now?

            You are looking for someone to give you an 'instant fix' (not to mention you post a query for every error of the same type) without even understanding your problem properly, which is essentially not going to help you in the longer run. I am wanting you to understand the basics so that you will be able to solve the problem yourself. Therefore, do what Cédric asked you to do[^]

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

            P Offline
            P Offline
            Purish Dwivedi
            wrote on last edited by
            #15

            I'm not getting that what to do? Plz help me. thanks.

            C 1 Reply Last reply
            0
            • P Purish Dwivedi

              I'm not getting that what to do? Plz help me. thanks.

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

              Purish Dwivedi wrote:

              I'm not getting that what to do?

              Look, people here are willing to help but if you don't want to put any effort yourself, then you can forget about it. The article I linked to you contains a lot of information about unicode and non-unicode builds. Once you have read the article, you will understand that to support both unicode and non-unicode builds, you will need to use TCHAR (and not char) and all the unicode-independant string manipulation routines (instead of strcpy, strlen, strtok, ...). For ALL of those functions, if you look in the MSDN documentation, you have a table that compares the different versions. You always have to use the "TCHAR.h routine" version.

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

              R 1 Reply Last reply
              0
              • C Cedric Moonen

                Purish Dwivedi wrote:

                I'm not getting that what to do?

                Look, people here are willing to help but if you don't want to put any effort yourself, then you can forget about it. The article I linked to you contains a lot of information about unicode and non-unicode builds. Once you have read the article, you will understand that to support both unicode and non-unicode builds, you will need to use TCHAR (and not char) and all the unicode-independant string manipulation routines (instead of strcpy, strlen, strtok, ...). For ALL of those functions, if you look in the MSDN documentation, you have a table that compares the different versions. You always have to use the "TCHAR.h routine" version.

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

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

                Cedric Moonen wrote:

                unicode-independant string manipulation routines

                Would that be rather character set independent string manipulation routines? OK, I'm just being a nitpick. :-D

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

                C 1 Reply Last reply
                0
                • R Rajesh R Subramanian

                  Cedric Moonen wrote:

                  unicode-independant string manipulation routines

                  Would that be rather character set independent string manipulation routines? OK, I'm just being a nitpick. :-D

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

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

                  Rajesh R Subramanian wrote:

                  Would that be rather character set independent string manipulation routines?

                  To be honnest, I didn't know the exact terminology. Now I know :)

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

                  1 Reply Last reply
                  0
                  • P Purish Dwivedi

                    Code Segment is token=strtok(userid,_T(";")); What about this error? 'strtok' : cannot convert parameter 2 from 'const wchar_t [2]' to 'const char *'

                    CPalliniC Offline
                    CPalliniC Offline
                    CPallini
                    wrote on last edited by
                    #19

                    It looks like you're doing a UNICODE build, but, neverthless, userid is declared as char * (or char userid[]) insetad of TCHAR * and, moreover, you're not using the generic text equivalent of strtok (i.e. _tcstok). :)

                    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]

                    In testa che avete, signor di Ceprano?

                    1 Reply Last reply
                    0
                    • P Purish Dwivedi

                      If it is 'strlen' : cannot convert parameter 1 from 'TCHAR [20]' to 'const char *' then what to do?

                      S Offline
                      S Offline
                      softwaremonkey
                      wrote on last edited by
                      #20

                      As someone else mentioned, it looks like you have some mixed UNICODE and ANSI problems. Ti make the code portable, make sure you have included "TCHAR.H" and use _tcslen instead of strlen. That should fix the problem. Tony

                      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