info-c digest vol 1 number 26

Alan_T._Cote.OsbuSouth at Xerox.COM Alan_T._Cote.OsbuSouth at Xerox.COM
Tue Apr 12 06:00:00 AEST 1988


In article <6476 at dhw68k.cts.com>, "David H. Wolfskill" <david at dhw68k.cts.COM>
writes,

>terminating NUL, character by character.  Then (assuming suitable
>definitions of the variables in question), 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)

(I hope I never have to maintain any of your code ;-)

If you are assuming the implementation of strcpy() presented below, your code is
likely to run for a very *long* time.  Your terminating NUL is overwritten with
ch before it is used to terminate the copy!

char *strcpy(dst,src)

char *dst, *src;

{

char *sv_dst;

sv_dst = dst;

while( *src != 0 )
  *dst++ = *src++;

return( sv_dst );

}



More information about the Comp.lang.c mailing list