void _splitpath( const char *path, char *drive, char *dir, char *fname, char *ext);
其中ext必须是已经分配了内存空间的字符串指针,否则会出错(c语言的基本特性,我就不赘述了)
下面再附上一段完整的示例程序,供大家参考:
#include <stdlib.h> #include <stdio.h> void main( void ) { char path_buffer[_MAX_PATH]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _makepath( path_buffer, "c", "\\sample\\crt\\", "makepath", "c" ); printf( "Path created with _makepath: %s\n\n", path_buffer ); _splitpath( path_buffer, drive, dir, fname, ext ); printf( "Path extracted with _splitpath:\n" ); printf( " Drive: %s\n", drive ); printf( " Dir: %s\n", dir ); printf( " Filename: %s\n", fname ); printf( " Ext: %s\n", ext ); } OutPut: Path created with _makepath: c:\sample\crt\makepath.c Path extracted with _splitpath: Drive: c: Dir: \sample\crt\ Filename: makepath Ext: .c