/* DEMO5 We move the copy loop into a function and see that no code need be changed except that we put our arg names in the while loop. We no longer need our extra vars char *word_ptr and *name_ptr in main. */ #include #include #include void myStrcpy( char *dest, char *src); int main() { char word[10]; char *name = malloc( 10 * sizeof(char) ); strcpy( name, "timothy" ); myStrcpy( word, name ); /* we are NOT changing the addresses in these 2 pointers */ printf("my name is: %s\n", word ); free( name ); return 0; } void myStrcpy( char *dest, char *src) { while ( (*dest++ = *src++) ); return; }