Re: Comment on trim string function please
- From: sebastian <sebastiangarth@xxxxxxxxx>
- Date: Sun, 13 Jul 2008 13:50:39 -0700 (PDT)
Doing such things as returning malloc'ed memory, checking for NULL, or
returning a pointer to the first non-space will generally lead to
misuse. Just keep it simple:
char*
trim( char* str )
{
char
* cpy = str,
* seq = str,
* fin = str + strlen( str ) - 1;
while( seq <= fin && isspace( *seq ) )
++seq;
while( seq <= fin && isspace( *fin ) )
--fin;
while( seq <= fin )
*cpy++ = *seq++;
*cpy = 0;
return str;
}
I can't guarantee that it's bug free of course...
.
- Follow-Ups:
- Re: Comment on trim string function please
- From: Eric Sosman
- Re: Comment on trim string function please
- From: sebastian
- Re: Comment on trim string function please
- References:
- Comment on trim string function please
- From: swengineer001@xxxxxxxxx
- Re: Comment on trim string function please
- From: Jens Thoms Toerring
- Re: Comment on trim string function please
- From: Bill Reid
- Re: Comment on trim string function please
- From: Willem
- Re: Comment on trim string function please
- From: Bill Reid
- Re: Comment on trim string function please
- From: Ben Bacarisse
- Re: Comment on trim string function please
- From: Bill Reid
- Re: Comment on trim string function please
- From: Ben Bacarisse
- Comment on trim string function please
- Prev by Date: Re: Commandline compiler for windows?
- Next by Date: Re: Commandline compiler for windows?
- Previous by thread: Re: Comment on trim string function please
- Next by thread: Re: Comment on trim string function please
- Index(es):
Relevant Pages
|