How about something like this, using the index function mentioned
earlier in posts :D

char *remove_apos( const char *remove )
{
    char buf[MSL], temp[MSL], *point, *apos;

    point = remove;
    buf[0] = '\0';
    while ( ( apos = index( point, '\'' ) ) != NULL )
    {
        strncpy(temp, point, apos - point);
        strcat(buf, temp);
        point = apos + 1;
    }
    strcat(buf, point);

    return buf;
}

I haven't tested it out or anything, but it looks like it should work,
strncpy just copies a certain number of char's from one string into
another, so theoretically it should see point (we'll say it starts at
1000), then if it finds an ' at the 4th character (1003), it will copy
the contents from 1000 of a size of 1003 - 1000, or 3 characters, into
the destination string, and then tack that onto the end of the growing
buf string, and set point's pointer equal the space after the ', then
loop it all over again... when it can't find anymore apostrophes (or if
there aren't any to begin with), it'll tack whatever's left from point
to the \0 character onto buf, and return buf... so the proper syntax for
this call would be something like this:

apos_free_string = remove_apos( apos_string );

you could make it into a void function also, if altering the contents of
the original string doesn't matter, and then just call it by
"remove_apos( string )"... and some minor alterations of the function
itself... hope this helps :D

Richard Lindsey 

-----Original Message-----
From: Mervine, Keith [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 12, 2004 1:46 PM
To: [email protected]
Subject: Odd function request remove_apostrophe

Lo all,
        I need a small function that will remove any apostophes from a
given string.

Example:

A Herald's Handbook

I would like to have read by the mud as

A Heralds Handbook

But only when the string is run through the function.

**remove_apos(string);**

I've tried to wrap my head around it but it came up empty.

Thanks in advance!

-K

-- 
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom

Reply via email to