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. call strcpy???????????

call strcpy???????????

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

    hi there, following problem: char g_szOutputFile[_MAX_PATH]; CString pathname; now i want to copy pathname into g_szOutputFile and i call strcpy(g_szOutputFile,pathname); but this doesn't look like it is working, are there any other functions i can call to convert a CString into a char? thank's in advance, patrick:confused:

    X D L R 4 Replies Last reply
    0
    • L Lost User

      hi there, following problem: char g_szOutputFile[_MAX_PATH]; CString pathname; now i want to copy pathname into g_szOutputFile and i call strcpy(g_szOutputFile,pathname); but this doesn't look like it is working, are there any other functions i can call to convert a CString into a char? thank's in advance, patrick:confused:

      X Offline
      X Offline
      XKent
      wrote on last edited by
      #2

      Strange, it's alwayse working perfectly (and doing so now!) But try to use LPTSTR GetBuffer( int nMinBufLength ); char *c; CString S; c = S.Getbuffer(10)

      1 Reply Last reply
      0
      • L Lost User

        hi there, following problem: char g_szOutputFile[_MAX_PATH]; CString pathname; now i want to copy pathname into g_szOutputFile and i call strcpy(g_szOutputFile,pathname); but this doesn't look like it is working, are there any other functions i can call to convert a CString into a char? thank's in advance, patrick:confused:

        D Offline
        D Offline
        David Fleming
        wrote on last edited by
        #3

        I'm pretty new to C++, but it seems to me that you can just cast the CString. I believe you need an LPTCSTR type for the strcpy function, so I think you can do a simple cast from CString to the LPTCSTR type: ...(LPTCSTR)pathname... You may need to cast it again such as: ...(LPTSTR)(LPTCSTR)pathname... David.

        L 1 Reply Last reply
        0
        • D David Fleming

          I'm pretty new to C++, but it seems to me that you can just cast the CString. I believe you need an LPTCSTR type for the strcpy function, so I think you can do a simple cast from CString to the LPTCSTR type: ...(LPTCSTR)pathname... You may need to cast it again such as: ...(LPTSTR)(LPTCSTR)pathname... David.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You can try it as such: char szFileName[MAX_LENGTH]; CString pathname = "c:\temp"; strcpy(szFileName, (const char*)pathname);:suss: :cool: :cool:

          L 1 Reply Last reply
          0
          • L Lost User

            You can try it as such: char szFileName[MAX_LENGTH]; CString pathname = "c:\temp"; strcpy(szFileName, (const char*)pathname);:suss: :cool: :cool:

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            thank's a lot guys, you helped me a lot:) :) :) patrick

            1 Reply Last reply
            0
            • L Lost User

              hi there, following problem: char g_szOutputFile[_MAX_PATH]; CString pathname; now i want to copy pathname into g_szOutputFile and i call strcpy(g_szOutputFile,pathname); but this doesn't look like it is working, are there any other functions i can call to convert a CString into a char? thank's in advance, patrick:confused:

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              I Think strncpy should be used for "safer" strcpy #define STRCPY(d,s) strncpy( (d), (s), sizeof( (s) ) - 1 );\ (d)[ sizeof((d)) - 1 ] = NULL;\ STRCPY( g_szOutputFile, pathname );

              1 Reply Last reply
              0
              • L Lost User

                hi there, following problem: char g_szOutputFile[_MAX_PATH]; CString pathname; now i want to copy pathname into g_szOutputFile and i call strcpy(g_szOutputFile,pathname); but this doesn't look like it is working, are there any other functions i can call to convert a CString into a char? thank's in advance, patrick:confused:

                R Offline
                R Offline
                realJSOP
                wrote on last edited by
                #7

                you can use one of these: strcpy(g_szOutputFile, (const char*)pathname); strcpy(g_szOutputFile, (LPCTSTR)pathname); strcpy(g_szOutputFile, (LPSTR)pathname); strcpy(g_szOutputFile, pathname.GetBuffer(pathname..GetLength())); pathname.ReleaseBuffer();

                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