Original Post
If I have a char thats holds a file path (ie: c:\blah\programs\whatever\gamedev.exe), how would I go about truncating it to just "gamedev.exe".
bool GetFileName(char *filePath, char *fileName)
// IN: filePath is a valid string containing the complete path.
// OUT: fileName is a char array containing at least as many characters as the file name, plus one.
// OUT: returns true if operation succeeded, false otherwise.
{
char *temp = filePath;
unsigned long index = strlen(temp);
bool isValid = false;
while(index >= 0)
{
if(temp[index] == '/' || temp[index] == '\\')
{
isValid = true;
break;
}
--index;
}
if(!isValid)
return false;
index ++;
unsigned long index2 = 0;
while(temp[index])
fileName[index2++] = temp[index++];
fileName[index2] = 0;
return true;
}

This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more