Newsgroups: comp.lang.c Path: utzoo!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps From: flaps@dgp.toronto.edu (Alan J Rosenthal) Subject: Re: strcpy Message-ID: <8804091440.AA02433@explorer.dgp.toronto.edu> Organization: University of Toronto References: <7712@apple.Apple.Com> <7485@brl-smoke.ARPA> <10731@mimsy.UUCP> <7506@brl-smoke.ARPA> <4251@hoptoad.uucp> <6286@dhw68k.cts.com> <4215@ihlpf.ATT.COM> <6476@dhw68k.cts.com> Date: Sat, 9 Apr 88 08:40:50 EDT david@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."