split a pathname into node, directory, file name, and extension
#include <stdlib.h> void _splitpath( const char *path, char *node, char *dir, char *fname, char *ext );
The _splitpath() function splits up a full pathname into four components, consisting of:
The argument path points to a buffer containing the full pathname to be split up.
The maximum size required for each buffer is specified by the manifest constants _MAX_PATH, _MAX_NODE, _MAX_DIR, _MAX_FNAME, and _MAX_EXT, which are defined in <stdlib.h>.
The arguments node, dir, fname and ext will not be filled in if they're NULL pointers.
For each component of the full pathname that isn't present, its corresponding buffer is set to an empty string.
#include <stdio.h> #include <stdlib.h> void main() { char full_path[ _MAX_PATH ]; char node[ _MAX_NODE ]; char dir[ _MAX_DIR ]; char fname[ _MAX_FNAME ]; char ext[ _MAX_EXT ]; _makepath(full_path,"//0","/home/fred/h","stdio","h"); printf( "Full path is: %s\n\n", full_path ); _splitpath( full_path, node, dir, fname, ext ); printf( "Components after _splitpath\n" ); printf( "node: %s\n", node ); printf( "dir: %s\n", dir ); printf( "fname: %s\n", fname ); printf( "ext: %s\n", ext ); }
produces the output:
Full path is: //0/home/fred/h/stdio.h Components after _splitpath node: //0 dir: /home/fred/h/ fname: stdio ext: .h
WATCOM
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
_fullpath(), _makepath(), _splitpath2()