by LocalMan · 13y ago · 0 comments
Just to read it and say what it did. This eliminated the vast majority of the applicants:
void strcpy(char x, char y) { while(x++ = y++); }
void strcpy(char *x, char *y) { while(*x++ = *y++); }
In this example, why does the loop terminate? Is it because the null terminator counted as a false? /* Copy SRC to DEST. */
char *
strcpy (dest, src)
char *dest;
const char *src;
{
char c;
char *__unbounded s = (char *__unbounded) CHECK_BOUNDS_LOW (src);
const ptrdiff_t off = CHECK_BOUNDS_LOW (dest) - s - 1;
size_t n;
do
{
c = *s++;
s[off] = c;
}
while (c != '\0');
n = s - src;
(void) CHECK_BOUNDS_HIGH (src + n);
(void) CHECK_BOUNDS_HIGH (dest + n);
return dest;
} void strcpy(char *x, char *y) { while(*x++ = *y++); }