Hi all.
I was trying Exercise 5-3 from the K&R book where you rewrite this function version using pointers:
Code:
void stringcat(char s[], const char t[]) {
int i, j;
i = j = 0;
while (s[i] != '\0')
i++;
while ((s[i++] = t[j++]) != '\0')
;
}
My solution (wrong) was to try something like this:
Code:
void stringcatp(char s[], const char t[]) {
while (*s++ != '\0')
;
while ((*s++ = *t++))
;
}
I finally gave up and looked at the solution:
Code:
void stringcatp(char s[], const char t[]) {
while (*s) /* find end of s */
s++;
while ((*s++ = *t++)) /* copy t */
;
}
However I am confused... what is the difference between while (*s) with s++ in the while body compared to my way?