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. strtok, Find the next token in a string

strtok, Find the next token in a string

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

    Hi I wan't to run my exe program and pass some arguments with the exe file. example: MyProgram.exe "nr1,nr2,nr3,nr4,nr5" This is some of the code: int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char *token; char seps[] = ","; token = strtok( lpCmdLine, seps ); This works ok in Visual C++, but i would like to do this in Emededd C++. There i get an error: error C2664: 'strtok' : cannot convert parameter 1 from 'unsigned short *' to 'char *' How can I do this right? Thanks!

    G J 2 Replies Last reply
    0
    • G gunnar66

      Hi I wan't to run my exe program and pass some arguments with the exe file. example: MyProgram.exe "nr1,nr2,nr3,nr4,nr5" This is some of the code: int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char *token; char seps[] = ","; token = strtok( lpCmdLine, seps ); This works ok in Visual C++, but i would like to do this in Emededd C++. There i get an error: error C2664: 'strtok' : cannot convert parameter 1 from 'unsigned short *' to 'char *' How can I do this right? Thanks!

      G Offline
      G Offline
      GDavy
      wrote on last edited by
      #2

      try casting your lpCmdLine var to char* strtok( (char*)lpCmdLine, seps ); It seems strange, cuz LPSTR is an ANSI string... Hope this helps you, Davy

      A J 2 Replies Last reply
      0
      • G GDavy

        try casting your lpCmdLine var to char* strtok( (char*)lpCmdLine, seps ); It seems strange, cuz LPSTR is an ANSI string... Hope this helps you, Davy

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        This works ok Thanks

        1 Reply Last reply
        0
        • G gunnar66

          Hi I wan't to run my exe program and pass some arguments with the exe file. example: MyProgram.exe "nr1,nr2,nr3,nr4,nr5" This is some of the code: int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char *token; char seps[] = ","; token = strtok( lpCmdLine, seps ); This works ok in Visual C++, but i would like to do this in Emededd C++. There i get an error: error C2664: 'strtok' : cannot convert parameter 1 from 'unsigned short *' to 'char *' How can I do this right? Thanks!

          J Offline
          J Offline
          jan larsen
          wrote on last edited by
          #4

          gunnar66 wrote: error C2664: 'strtok' : cannot convert parameter 1 from 'unsigned short *' to 'char *' It seems like you've defined UNICODE (or _UNICODE, I can't remember the definition for compiling for unicode precisely). If thats the case, then LPSTR translates to unsigned short * instead of char *. strtok requires char * parameters, if you intended to use unicode strings, you should use wcstok instead. [EDIT]A GDavy has corrected me, LPSTR should be defined as CHAR * and CHAR should again be defined as char. But if the code you've given us is the same you're using for your embedded version, then somehow LPSTR must be defined as unsigned short *[/EDIT] "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

          1 Reply Last reply
          0
          • G GDavy

            try casting your lpCmdLine var to char* strtok( (char*)lpCmdLine, seps ); It seems strange, cuz LPSTR is an ANSI string... Hope this helps you, Davy

            J Offline
            J Offline
            jan larsen
            wrote on last edited by
            #5

            GDavy wrote: It seems strange, cuz LPSTR is an ANSI string... Not if you are compiling for unicode, then LPSTR is unsigned short *. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

            G 1 Reply Last reply
            0
            • J jan larsen

              GDavy wrote: It seems strange, cuz LPSTR is an ANSI string... Not if you are compiling for unicode, then LPSTR is unsigned short *. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

              G Offline
              G Offline
              GDavy
              wrote on last edited by
              #6

              Nono, LPTSTR is a Unicode format (wide char) in UNICODE and ANSI when not compiling for UNICODE LPSTR is always ANSI string (8bit) LPWSTR is always wide char string(16 bit) But I used to be confused by these too.. Greetz, Davy

              J 1 Reply Last reply
              0
              • G GDavy

                Nono, LPTSTR is a Unicode format (wide char) in UNICODE and ANSI when not compiling for UNICODE LPSTR is always ANSI string (8bit) LPWSTR is always wide char string(16 bit) But I used to be confused by these too.. Greetz, Davy

                J Offline
                J Offline
                jan larsen
                wrote on last edited by
                #7

                :-O:doh: You're so right. But regardless, it seems that something makes his compiler believe that LPSTR is defined as unsigned short *. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus

                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