strcpy
Alan J Rosenthal
flaps at dgp.toronto.edu
Sat Apr 9 22:40:50 AEST 1988
david at dhw68k.cts.com (David H. Wolfskill) writes:
>Suppose...
[
strcpy's order were implementation-defined, and this implementation
defined it as being left-to-right.
]
>Then, an algorithm to clear a given
>string (str1) to a given value (other than NUL) could be coded:
>
> *str1 = ch;
> for (c1 = str1; *++c1 != '\0'; *c1 = *(c1 -1));
>
>or (remembering the characteristics of the implementation):
>
> *str1 = ch;
> strcpy(str1+1, str1)
>
>but I think the latter is easier to comprehend.
Gosh, I find these both really complicated. (I must say however that
the most complicated part of the first example is the fact that the
_for_ body is placed inside the control structure, and the increment
inside the test!)
Why not do the simple:
for(p = str1; *p; p++) /* optionally insert "!= '\0'" */
*p = ch;
ajr
--
"Comment, Spock?"
"Very bad poetry, Captain."
More information about the Comp.lang.c
mailing list