TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Kurt Kuzba
from: Bob Stout
date: 2003-09-23 07:00:44
subject: Re: Snippets ini.c

From: rbs{at}snippets.org
To: c_echo{at}yahoogroups.com

On Tue, 23 Sep 2003, Kurt Kuzba wrote:

> JB>  also all-space strings are reduced to a single space instead
> JB>  of empty. (can be fixed by initializing iterator to -1 in the
> JB>  for loop)
>
> Had I thought of it, I would have added a line testing the value of
> "space".

I did think of it... You may recall that I mentioned that before posting it
to SNIPPETS, I renamed the function to rmtrail() and replaced your test
harness with mine? Well, the first two "strings" I pass in testing are
NULL and "". To this, I just added " ", and it still works.

> JB>  For long strings determining the length first and then working
> JB>  backwards may be more efficient like Bob Stout's code.
>
> Maybe, but you are stepping through the string and then backing
> up in that case, and I wanted to just go through it one time and
> call it done.  That is why I have the separate variable to recall
> the position of the last non-space char value, and make it the
> final character in the string.

This is at the heart of the argument for the "two pass" approach. Aside
from the fact that it has a clearly obvious algorithm, many (most?)
compiler libraries will have implemented strlen() in assembly which may
make it faster than anything you can write in C.

-------------------------------------------------------------
Consulting: http://www.MicroFirm.biz/
Web graphics development: http://Image-Magicians.com/
Software archives: http://snippets.snippets.org/
  c.snippets.org/   cpp.snippets.org/      java.snippets.org/
  d.snippets.org/   python.snippets.org/   perl.snippets.org/
  dos.snippets.org/ embedded.snippets.org/ apps.snippets.org/
Audio and loudspeaker design:
  http://LDSG.snippets.org/   http://www.diyspeakers.net/

--- SoupGate-Win32 v1.05
* Origin: rbs{at}snippets.org (2:292/516.666)
SEEN-BY: 633/267 270
@PATH: 292/516 854 140/1 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.