Comparing strings...
Mark A Terribile
mat at mole-end.UUCP
Sun Oct 21 11:00:09 AEST 1990
> > int strcmp(char *s,char *t)
> > {
> > for (; *s && *s == *t; s++,t++);
> > return *s-*t;
> > }
> --Andrew Koenig
> ark at europa.att.com
Note the semicolon on the for(;;) . Note that it's hard to note.
Another article on this topic replaced a null statement for a loop body
with a continue :
while( . . . . . )
continue;
IMnsHO, the semicolon null statement is one of the more irritating glitches
in C. I prefer
for( ; *s && *s == *t; s++, t++ )
{}
or
while( . . . )
{}
It's quite clear that this is an empty, no-effect statement. It's a brace-
thing where you expect a brace-thing, and it won't get missed on a faint
printout the way a semicolon can be.
--
(This man's opinions are his own.)
From mole-end Mark Terribile
More information about the Comp.lang.c
mailing list