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