Mail Archives: djgpp/1997/10/02/03:30:25
On 29 Sep 1997, Steve Laisch wrote:
> In Visual Basic and Visual C++/MFC their is a useful
> command called TrimRight() which will take a string and
> trim all the whitespace off the right side of the string.
>
> Atleast _I_ think its useful :-) Is their anything similiar
> in regular ANSI C in DJGPP? I'm not even sure if GXX(C++) has
> anything like it but I need a C counterpart and all my
> C texts before 1987 don't have one(Yes, I need to buy
> books more often :-)
If you're using plain C-type strings (ie: char *'s), you can do something
like this:
#include <string.h>
#include <wtype.h>
void trim_right(char * str)
{
int index = strlen(str);
while (index && isspace(str[index]))
{
str[index] = '\0';
index--;
}
}
That *should* work. I haven't tested it and my vanilla C is a little
rusty, but I'm pretty confident. ;) If it doesn't, mail me and I'll see
what I can do to fix it.
/\/\att /\/\astracci mmastrac AT acs DOT ucalgary DOT ca
GCS/GE d- s+:+ a--- C++++ UA P+ L E-- W+ N++ o K+ w+ O M- V
PS++ PE++ Y+ PGP t+++ 5+++ X++ R++ tv+ b+++ DI++++ I
G++ e h r* z?
- Raw text -