Re: Tryiing just to read/understand this code



On Mon, 28 Aug 2006 10:48:24 -0700, jmcgill
<jmcgill@xxxxxxxxxxxxxxxxx> wrote:

smnoff wrote:
Is line 512 to 521 of the IF statement seen as the single and only line of
the WHILE loop in Line 511?

Yeah. And I totally refuse to buy any argument I've ever heard
against using brackets on control structures, even when they are only
one-statement blocks.

In my shop, you'd format it like this, or maybe you'd be happier
elsewhere :-)

strstr(const char *as1, const char *as2)
{
const char *s1,
*s2;
const char *tptr;
char c;

s1 = as1;
s2 = as2;

if (s2 == NULL || *s2 == '\0') {
return ((char *) s1);
}
c = *s2;

while (*s1) {
if (*s1++ == c) {
tptr = s1;
while ((c = *++s2) == *s1++ && c);
if (c == 0) {
return ((char *) tptr - 1);
}
s1 = tptr;
s2 = as2;
c = *s2;
}
}
return (NULL);
}


Ugh!

Oz
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.



Relevant Pages

  • Re: Tryiing just to read/understand this code
    ... against using brackets on control structures, ... strstr(const char *as1, const char *as2) ... const char *tptr; ...
    (comp.lang.c)
  • Re: Tryiing just to read/understand this code
    ... In my shop, you'd format it like this, or maybe you'd be happier ... strstr(const char *as1, const char *as2) ... I would also point out that the user is not allowed to write a function named strstr with external linkage so I assume this is discussing possible implementations the library could use. ... const char *tptr; ...
    (comp.lang.c)