wrote:
>
> have a bit of c code that is ment to take a string (that may or
> may not have spaces before or after the string) i.e. " stuff ",
> and trims off the whitespace before and after.
> Code:
>
> char *trim (char *str, char ch)
Untested:
char *trim(char *s, char ch)
{
char *p;
if (s && *s && ch) { /* avoid evil cases */
while (ch == *s) s++; /* trims leading. */
p = s; /* must be advanced over entry */
while (*p) p++; /* find end of string */
p-- /* last char in string */
while ((p > s) && (ch == *p)) p--;
*p = '\0';
}
return s; /* ok in evil cases */
}
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson