Syntax
#include <stdlib.h> void _splitpath(char *path, char *drive, char *dir, char *fname, char *ext);Description
The maximum size necessary for each buffer is specified by the _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, and _MAX_EXT constants defined in <stdlib.h>. The other arguments point to the following buffers used to store the path name elements: compact break=fit.
Buffer
You can specify NULL for any of the buffer pointers to indicate that you do not want the string for that component returned.
The return parameters contain empty strings for any path name components not found in path.
There is no return value.
This example builds a file name path from the specified components, and then extracts the individual components.
#include <stdio.h>#include <stdlib.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", "qc\\bob\\eclibref\\e", "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("directory: %s\n", dir); printf("file name: %s\n", fname); printf("extension: %s\n", ext); return 0; /**************************************************************************** The output should be: Path created with _makepath: c:qc\bob\eclibref\e\makepath.c Path extracted with _splitpath: drive: c: directory: qc\bob\eclibref\e\ file name: makepath extension: .c ****************************************************************************/ }Related Information