TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BOB STOUT
from: ANTON S. MAXIMENKO
date: 1997-07-03 01:09:00
subject: String manipulation

    Best wishes,  Bob !
 >> Use simply circle (such us _while_) and scan your string for a point. If
 >> you'll find point - change last three symbols, if not - add point, three
 >> symbols of extantion and /0 symb. at the and of string.
 BS> Anton...
    Here I am :)
 BS>   Some obvious problems:
 BS> 1.  Periods can (and do) sometimes appear in directory names, so the
 BS> search    algorithm *has* to start at the end and work backwards.
    Good idea. But I talked about very simple algorithm... My hope was in 
that fact, that my idea is only starting point...
 BS> 2.  Even starting at the end, once you find a period, you must then
 BS> find
 BS> out    if there's a path delimiter ('/' or '\\') to the right of it 
hich
 BS> would    indicate an embedded directory name.
    But I don't see any difficulty.  You can get name once you found this 
character or "head" of string.
 BS> 3.  You can't make any assumptions about the length of the extension,
 BS> which    may be 1, 2, 3, or *0* characters long. The greatest impact
 BS> on
 BS> the algo-    rithm is the case where the original file had no extension
 BS> and therefore    your search for a period may have been in vain.
    Of course ! Don't think I'm so fool ! But, I think, better give hint to a 
man and let him boil his brains himself.
    My variant. It should completely work.
-------------------------------
    #include 
void main ()
  {
    int position = 0;
    char Filename[8];
    char String[128];
   ..... // get your string
    int i=0;
    if(Filename[0] != 0)
       while (i !=0)
           {
           if(String[i] == '\') position = i+1;
           i++;
           } // We will move position until we find last '\'
              // Next  cars sould be filename with extention
      int j=0;
      while(String[position] != '.'|| String[position] != NULL)
          {
           Filename[j] = String[position];
           j++;
           position++;
          }
      Filename[position] = NULL; // Lock vector by NULL character.
          }
-------------------
    So, we can do it movig forward as well, as backward :)  At the first step 
we find last name (last name will be name of file) and we wil get it :)
    If we need extention, we can after second step using 'position' get 
extantion.
                                               Hiding in the grave
                                                     Anton S. Maximenko
--- GoldED/386 2.50+
---------------
* Origin: Night is so beautiful (we need her as we need Day) (2:5020/535.29)

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™.