There are a few problems with that, you better run it yourself to find
out. However, I'll provide some code.
char* strip( const char* argument, char rem )
{
char static buf[MSL];
char* paste = buf;
for( ; *argument; argument++ )
{
if( *argument == rem ) continue;
*(paste++) = *argument;
}
*paste = '\0';
return buf;
}
This will strip the `argument' of any occurence of the char `rem' and
return a new string. You may also hardcode the `rem' with the value '\''
OR make your function
char *remove_apos( char* argument ) { return strip( argument, '\'' ); }
Htam
Richard Lindsey wrote:
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