>> void ChangeExt(char * NewName,char * OldName,char * NewExt)
>> {
>> char * Temp;
>> strcpy(NewName,OldName); // Make copy of OldName
>> Temp = strchr(NewName,'.'); // Finding dot in OldName
>> if(Temp)
>> strcpy(Temp,NewExt); // If dot present, cnange
>> extention else strcat(NewName,Ext); // else
>> adding extention to NewName
>> }
BS> Sadovnikov...
BS> Try it with a path name like
BS> \root.dir\foo\bar\foo.bar\wumpus.txt and you'll see some of the
BS> problems that the SNIPPETS code knows how to avoid. ;-)
So, let's search dot from the end of string:
char * SearchDot(char * Name) // Return a dot pos in a file name or NULL
// if file name does not have extention
{
int Len = strlen(Name);
for(int n = Len - 1;n >= 0;n ++)
{
if(Name[n] == '.')
return Name + n;
if(Name[n] == '\\') // If file name does not have
extention
return NULL;
}
return NULL;
}
void ChangeExt(char * NewName,char * OldName,char * Ext)
{
char * DotPos;
strcpy(NewName,OldName);
DotPos = SearchDot(NewName);
if(DotPos)
strcpy(DotPos,Ext);
else
strcat(NewName,Ext);
}
Commander Wolf
--- 2.50+
---------------
* Origin: *) Commander Wolf (* Moscow, Russia (2:5020/760.14)
|