分析路径参数函数_splitpath

以前也写过分析程序运行路径的博文http://blog.csdn.net/qiuyeting/article/details/7305077,但今天偶然发现有更好的函数可以帮助我们分析路径参数。这个函数就是_splitpath

函数原型:

void _splitpath(
   const char *path,
   char *drive,
   char *dir,
   char *fname,
   char *ext 
);
void _wsplitpath(
   const wchar_t *path,
   wchar_t *drive,
   wchar_t *dir,
   wchar_t *fname,
   wchar_t *ext 
);
参数含义:

path

Full path buffer. _makepath does not check that path does not exceed _MAX_PATH.

drive

Drive letter.

dir

Directory path.

fname

File name.

ext

File name extension.

实例:

#include <stdlib.h>
#include <stdio.h>
#include <string.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];

   //获取当前运行程序的完整路径,赋值给path_buffer
   strcpy(path_buffer,__argv[0]);
   _splitpath( path_buffer, drive, dir, fname, ext ); 
   // 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 );

   return 0;
}

运行结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值