Ok, if i have a string named Title, and it equals "C:\blah\foo\test.txt", how do i get Title to equal "test.txt". This is what i tried...
strcpy(Title, szFileName);
strrev(Title);
Title[atoi(strchr(Title, '\\'))] = 0;
strrev(Title);
But it doesnt work.
parksie
Dec 18th, 2000, 04:41 PM
Use the splitpath function.
From MSDN:
/* MAKEPATH.C */
#include <stdlib.h>
#include <stdio.h>
void 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" );
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( " Dir: %s\n", dir );
printf( " Filename: %s\n", fname );
printf( " Ext: %s\n", ext );
}