现在的位置: 首页 > 综合 > 正文

用_splitpath 函数可以分解出路径,文件名,扩展名,msdn的例子

2011年03月24日 ⁄ 综合 ⁄ 共 596字 ⁄ 字号 评论关闭
#include <stdlib.h> 
#include <stdio.h> 
 
int 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 " ); // C4996 
    // Note: _makepath is deprecated; consider using _makepath_s instead 
    printf( "Path created with _makepath: %s"n"n ", path_buffer ); 
    _splitpath( path_buffer, drive, dir, fname, ext ); // C4996 
    // Note: _splitpath is deprecated; consider using _splitpath_s instead 
    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 ); 
}

抱歉!评论已关闭.