Let us examine four ways of how we can copy strings. These functions have the following preconditions:
/* Array subscript version */ void astrcopy (char s[], char t[]) { // or (char* s, char* t) int i = 0; while ((t[i] = s[i]) != '\0') i++; } /* Pointer version 1 */ void p1strcopy (char* s, char* t) { int i = 0; while ((*(t+i) = *(s+i)) != '\0') i++; } /* Pointer version 2 */ void p2strcopy (char* s, char* t) { while ((*t++ = *s++) != '\0') ; } /* Pointer version 3 */ void p3strcopy (char* s, char* t) { while (*t++ = *s++) ; }