Skip to main content
gamedev.net
🔒 Locked

some file path string help

Started by fireking Nov 19, 2003 at 8:53 PM 3 replies 350+ views
Original Post
fireking
fireking
ok, the following code will take variable filename, and get all text from it, except for the last 4 characters (ie: ".ext") (name is already defined as "unsigned char *name;")
char *capfilename;
int nlen=(int)strlen(filename);
capfilename=new char[(nlen)+1];
for(int i=0;i<=nlen;i++)
	capfilename[ i ]=tolower(filename[ i ]);
name = new char[(nlen-4)+1];
for(int i=0;i

(yes im being very careful about my data, even deleting the strings, lol)

anyways, if you pass, lets say "C:/windows/something.bmp", the name is set to "C:/windows/something"

i need to know how to get rid of everything that comes before the last "/" without using strtok()

i have a feeling its going to involve using one of the "find last occurence of character in a string" functions

could anyone help me out?   
                        
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
Mastaba
Mastaba
If you are only targeting Windows, you might want to take a look at the various path functions. There is one for just about every conceivable operation.
pinacolada
pinacolada
int pos_of_last_slash = -1;
for (int i=0; i < nlen; i++)
  if (capfilename[i] == ''/'')
    pos_of_last_slash = i;
if (pos_pf_last_slash != -1)
  char *file_name_without_path = &capfilename[pos_of_last_slash+1]
Mastaba
Mastaba
In Windows:

PathStripPath(filename);

fireking
fireking
thanks mastaba

also thanks to pinacolada for the method that doesn''t require linking to shlwapi.lib
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.