Re: OFF-TOPIC C: delete_doubledollar

From: Sammy (samedi@clark.net)
Date: 07/07/96


On Sat, 6 Jul 1996, Ground Zero Enterprises wrote:

> 
> Would some nice person be nice enough to take some time out of thier busy 
> day to explain what the functionality of this is and how it works.  I 
> have been trying to figure it out, but without knowing what it is doing, 
> I can't figure out how it's doing it and vice-versa :P
> 
> char *delete_doubledollar(char *string)
> {
>   char *read, *write;
> 
>   if ((write = strchr(string, '$')) == NULL)
>     return string;

This part uses the strchr function to check the string for dollar signs.  
If there aren't any, then no action is necessary, so reutrn without 
modifying it.

>   read = write;

Read and write are pointers to the string we're working on.  They both 
start at the first character.

>   while (*read)

When you come across a null in the string it means you've hit the end of 
the string, so break out of the loop.

>     if ((*(write++) = *(read++)) == '$')

Copy the character pointed to by read into the one pointed to by write 
(yes they will normally point to the same place).  If that character 
happens to be a $, then execute the next two lines.

>       if (*read == '$')
>         read++;

If the last read was a dollar sign, check the next one.  If it's also a 
dollar sign, skip it.

>   *write = '\0';

After going through the whole string, put a null at the end in case it's 
any shorter than it used to be, so the string will be terminated in the 
right place.

>   return string;
> }

Now that I look at this, it kinda seems like a triple dollar sign will 
turn into a double.  I've never bothered to find out why we need to kill 
double dollars, so I don't know if it matters.  *shrug*

Sam



This archive was generated by hypermail 2b30 : 12/07/00 PST