I have also written a blog http://www.bkjia.com/kf/201203/125323.html for the analytics program running path, but today I accidentally found that there are better functions that can help us analyze path parameters. This function is _ splitpath.
Function prototype:
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
);
Parameter description:
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.
Instance:
[Cpp]
1. # include <stdlib. h>
2. # include <stdio. h>
3. # include <string. h>
4. int main (void)
5 .{
6. char path_buffer [_ MAX_PATH];
7. char drive [_ MAX_DRIVE];
8. char dir [_ MAX_DIR];
9. char fname [_ MAX_FNAME];
10. char ext [_ MAX_EXT];
11.
12. // obtain the complete path of the current running program and assign it to path_buffer.
13. strcpy (path_buffer ,__ argv [0]);
14. _ splitpath (path_buffer, drive, dir, fname, ext );
15. // Note: _ splitpath is deprecated; consider using _ splitpath_s instead
16. printf ("Path extracted with _ splitpath: \ n ");
17. printf ("Drive: % s \ n", drive );
18. printf ("Dir: % s \ n", dir );
19. printf ("Filename: % s \ n", fname );
20. printf ("Ext: % s \ n", ext );
21.
22. return 0;
23 .}
Running result:
Excerptioncontext