函数原型:
//Break a path name into components.
void _splitpath( const char
*path, char *drive, char
*dir, char *fname, char
*ext ); //ANSI
void _wsplitpath( const wchar_t *path, wchar_t *drive, wchar_t *dir, wchar_t *fname, wchar_t *ext );//UNICODE
//Create a path name from components.
void _makepath( char *path, const char *drive, const char *dir, const char *fname, const char *ext );
void _wmakepath( wchar_t *path, const wchar_t *drive, const wchar_t *dir, const wchar_t *fname, const wchar_t *ext );
参数都比较简单,不举例说明了
要包含头文件:#include <stdlib.h>
举例如下:
char szPath[] = "D:\program files\task\test.cpp";
char szDrive[MAX_PATH];
char szDir[MAX_PATH];
char szFileName[MAX_PATH];
char szExt[MAX_PATH];
//_splitpath(szPath, szDrive, szDir, szFileName, szExt);
//这里使用它的安全函数
_splitpath_s(szPath, szDrive, MAX_PATH, szDir, MAX_PATH, szFileName, MAX_PATH, szExt, MAX_PATH);
执行完该函数后,szDrive:"D:" szDir:"program files ask" szFileName:"test" szExt:".cpp"
char szFullPath[MAX_PATH] ={ 0 };
// _makepath(szFullPath, szDrive, szDir, szFileName, szExt);
//这里使用安全函数_makepath_s
_makepath_s(szFullPath, sizeof(szFullPath), szDrive, szDir, szFileName, szExt);
执行完后szFullPath的值为“D:program files ask est.cpp”