Mail Archives: djgpp/1998/09/04/08:16:01
In comp.os.msdos.djgpp (SED AT ticnet DOT com) writes:
>So I should be able to rewrite:
>
>while( (*p1 != '\0') && isspace( *p1 ) )
> ++p1;
>
>as
>
>while( (*p1 != '\0') && isspace( *(p1++) ) );
You could, but there would be a subtle change in functionality. In your
original code, p1 was incremented if the string hadn't ended and it pointed
to a spcae character. In the second line, p1 might be incremented one more
time: If the string hasn't ended and p1 point to a non-space character it
will still be incremented (because the increment is no longer conditional on
the success of the second clause). The loop will end in one of two ways:
1. The string is only space; p1 will point the the terminating chracter.
2. The string contains some non-space. The loop will terminate with p1
pointing to the character after the first non-space character (which will be
a '\0' if the string if there is only one non-space character followed by a
terminataing character.
eg
" \0" " abcx\0" "y\0"
^ ^ ^
Neil
--
Neil Townsend +44 (1865) 273121 neil AT robots DOT ox DOT ac DOT uk
- Raw text -