// different version of string copy // ---------------------------------------------- // version 1 // ---------------------------------------------- void copy_str(char *dst, char *src) { int i = 0; while (src[i] != '\0') { dst[i] = src[i]; ++i; } // copy last character '\0' dst[i] = src[i]; } // ---------------------------------------------- // version 2 // stop condition can be reduced to : src[i] // assignment dst[i] = src[i] has a value of src[i] // ---------------------------------------------- void copy_str(char *dst, char *src) { int i = 0; // while ((dst[i] = src[i]) != '\0') ++i; while (dst[i] = src[i]) ++i; } // ---------------------------------------------- // version 3 // use of pointers and post incrementation // ---------------------------------------------- void copy_str(char *dst, char *src) { while (*dst++ = *src++) ; }