There are two versions of string copy functions written in C. My question is why the version1 need "!= '\0'" but the version2 doesn't. What if I have a character 0 to be copied using version2, will the '0' terminate coping process?
void version1(char to[], char from[])
{
int i;
i = 0;
while ((to[i] = from[i]) != '\0')
++i;
}
char *version2(char *dest, const char *src)
{
char *addr = dest;
while (*dest++ = *src++);
return addr;
}
In addition, why an input like "1230456" will not terminate the coping since '0' appears in the middle of the string?
*dest++ = *src++is the same as(*dest++ = *src++) != 0. Read a C book.