TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BOB STOUT
from: SADOVNIKOV SERGEY
date: 1997-06-29 01:20:00
subject: String manipulation

 >> 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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.