Trimming path name

This is a discussion on Trimming path name within the C Programming forums, part of the General Programming Boards category; I am working with a program that needs to trim the path name down to just the filename. I am ...

  1. #1
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398

    Trimming path name

    I am working with a program that needs to trim the path name down to just the filename. I am using windows. This input is coming from a predetermined value in the registry. I was wondering what the best method of doing this would be.

    The method that I think would be the easiest would be this way:
    Code:
    char sTemp[1024];
    char newTitle[1024];
    
    //This approaches the first back slash from the right side of the string
    for (i = strlen(sTemp); i > 0; i--)
    	if (sTemp[i-1] == '\\')
    	{
    		strcpy(newTitle, sTemp[i-1]);
    		break;
    	}
    Unfortunately I get:
    Error 1 error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *
    This seems to be a good way to do it, but apparently I am confusing on what format to send my arguments to strcpy. Or maybe I should be using an entirely different function.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >Error 1 error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *
    > strcpy(newTitle, sTemp[i-1]);
    You want to pass the address of that element:
    strcpy(newTitle, &sTemp[i-1]);

  3. #3
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398
    ...Thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 10:13 AM
  2. clipping path
    By stanlvw in forum Windows Programming
    Replies: 0
    Last Post: 07-24-2008, 12:47 AM
  3. Can't figure out what keeps hanging up my program
    By shays in forum C Programming
    Replies: 7
    Last Post: 11-12-2007, 02:59 PM
  4. Path Finding Using Adjacency List.
    By DeepBlackMagic in forum C++ Programming
    Replies: 7
    Last Post: 05-16-2005, 03:34 PM
  5. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 03:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21