delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/02/03:30:25

From: Matthew Mastracci <mmastrac AT acs DOT ucalgary DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: GCC TrimRight?
Date: Tue, 30 Sep 1997 20:44:35 -0600
Organization: The University of Calgary
Lines: 38
Message-ID: <60sdfj$19u4@ds2.acs.ucalgary.ca>
References: <60pd04$47k$1 AT flood DOT xnet DOT com>
NNTP-Posting-Host: mmastrac AT acs2 DOT acs DOT ucalgary DOT ca
Mime-Version: 1.0
In-Reply-To: <60pd04$47k$1@flood.xnet.com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019