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. assigning string to char

assigning string to char

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 3 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.
  • T Offline
    T Offline
    Tara14
    wrote on last edited by
    #1

    Hello, I want to assign a string stored in a CString to char data type. I am unfamiliyar with char data types. They are, somehow, totally beyond my understanding! Basically, I am getting the path of a file in strFileName. I want to extract only the file name from it. This is what I am trying to do:

    if (dlg.DoModal() == IDOK)
    {
    strFileName.Format("%s",dlg.GetPathName());
    // Add to MRU list
    AfxGetApp()->AddToRecentFileList(strFN);

    // extract the file name
    char filePath\[\_MAX\_PATH\];
    char drive\[\_MAX\_DRIVE\];
    char dir\[\_MAX\_DIR\];
    char fname\[\_MAX\_FNAME\];
    char ext\[\_MAX\_EXT\];
    
    filePath = strFN;  // ---> this is wrong. Plz can you tell me the correct way.
    
    \_splitpath( filePath, drive, dir, fname, ext );
    CString st; st.Format("%s%s",fname,ext);
    SetWindowText(st);
    pDoc->IsNew = FALSE;
    

    }

    Thanks.

    _


    Fortitudine Vincimus!_

    D L 2 Replies Last reply
    0
    • T Tara14

      Hello, I want to assign a string stored in a CString to char data type. I am unfamiliyar with char data types. They are, somehow, totally beyond my understanding! Basically, I am getting the path of a file in strFileName. I want to extract only the file name from it. This is what I am trying to do:

      if (dlg.DoModal() == IDOK)
      {
      strFileName.Format("%s",dlg.GetPathName());
      // Add to MRU list
      AfxGetApp()->AddToRecentFileList(strFN);

      // extract the file name
      char filePath\[\_MAX\_PATH\];
      char drive\[\_MAX\_DRIVE\];
      char dir\[\_MAX\_DIR\];
      char fname\[\_MAX\_FNAME\];
      char ext\[\_MAX\_EXT\];
      
      filePath = strFN;  // ---> this is wrong. Plz can you tell me the correct way.
      
      \_splitpath( filePath, drive, dir, fname, ext );
      CString st; st.Format("%s%s",fname,ext);
      SetWindowText(st);
      pDoc->IsNew = FALSE;
      

      }

      Thanks.

      _


      Fortitudine Vincimus!_

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

      Tara14 wrote:

      I am unfamiliyar with char data types. They are, somehow, totally beyond my understanding!

      Yet you understand CString??

      Tara14 wrote:

      strFileName.Format("%s",dlg.GetPathName());

      Why not simply:

      strFileName = dlg.GetPathName();

      Tara14 wrote:

      filePath = strFN; // ---> this is wrong. Plz can you tell me the correct way. _splitpath( filePath, drive, dir, fname, ext );

      Should be:

      _splitpath(strFileName, NULL, NULL, fname, NULL);


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

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

      T 1 Reply Last reply
      0
      • T Tara14

        Hello, I want to assign a string stored in a CString to char data type. I am unfamiliyar with char data types. They are, somehow, totally beyond my understanding! Basically, I am getting the path of a file in strFileName. I want to extract only the file name from it. This is what I am trying to do:

        if (dlg.DoModal() == IDOK)
        {
        strFileName.Format("%s",dlg.GetPathName());
        // Add to MRU list
        AfxGetApp()->AddToRecentFileList(strFN);

        // extract the file name
        char filePath\[\_MAX\_PATH\];
        char drive\[\_MAX\_DRIVE\];
        char dir\[\_MAX\_DIR\];
        char fname\[\_MAX\_FNAME\];
        char ext\[\_MAX\_EXT\];
        
        filePath = strFN;  // ---> this is wrong. Plz can you tell me the correct way.
        
        \_splitpath( filePath, drive, dir, fname, ext );
        CString st; st.Format("%s%s",fname,ext);
        SetWindowText(st);
        pDoc->IsNew = FALSE;
        

        }

        Thanks.

        _


        Fortitudine Vincimus!_

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

        Hello, is this an CFileDialog Object, right??? Use:

        CString csFileName = FileOpenDlg.GetFileName();
        

        regards break;

        1 Reply Last reply
        0
        • D David Crow

          Tara14 wrote:

          I am unfamiliyar with char data types. They are, somehow, totally beyond my understanding!

          Yet you understand CString??

          Tara14 wrote:

          strFileName.Format("%s",dlg.GetPathName());

          Why not simply:

          strFileName = dlg.GetPathName();

          Tara14 wrote:

          filePath = strFN; // ---> this is wrong. Plz can you tell me the correct way. _splitpath( filePath, drive, dir, fname, ext );

          Should be:

          _splitpath(strFileName, NULL, NULL, fname, NULL);


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

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

          T Offline
          T Offline
          Tara14
          wrote on last edited by
          #4

          DavidCrow wrote:

          Should be: _splitpath(strFileName, NULL, NULL, fname, NULL);

          As simple as that!:-O! Silly me. Trying unnecessary stuff!! Thank you.

          _


          Fortitudine Vincimus!_

          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