/* * stringcopy-fixed - fixing a naive and buggy implementation of * copying strings * * CS50 Spring 2022 */ #include #include #include void stringcopy(char *sp, char *dp); int main() { char *src = "CS 50"; char dest[strlen(src)+1]; // char* dest; for option 2 // copy src to dest and print them out // solution option 2: dest = malloc(strlen(src)+1); stringcopy(src, dest); printf("src = '%s'\n", src); printf("dest = '%s'\n", dest); // solution option 2: free(dest); return 0; } /* stringcopy - copy string from source sp to destination dp */ void stringcopy(char *sp, char *dp) { while (*sp != '\0') { *dp++ = *sp++; } *dp = '\0'; }