Results 1 to 2 of 2

Thread: Damn string help, again.

  1. #1
    Guest

    Post

    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...

    Code:
    strcpy(Title, szFileName);
    strrev(Title);
    Title[atoi(strchr(Title, '\\'))] = 0;
    strrev(Title);
    But it doesnt work.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Use the splitpath function.

    From MSDN:
    Code:
    /* 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 );
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width