Thread: Trimming path name

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

    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
    404
    ...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, 09:13 AM
  2. clipping path
    By stanlvw in forum Windows Programming
    Replies: 0
    Last Post: 07-23-2008, 11:47 PM
  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 Geolingo in forum C++ Programming
    Replies: 7
    Last Post: 05-16-2005, 02:34 PM
  5. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM