diff --git "a/C/\345\212\250\346\200\201\345\210\206\351\205\215\345\206\205\345\255\230\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\213\267\350\264\235\345\244\247\345\235\221.c" "b/C/\345\212\250\346\200\201\345\210\206\351\205\215\345\206\205\345\255\230\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\213\267\350\264\235\345\244\247\345\235\221.c" new file mode 100644 index 0000000000000000000000000000000000000000..40a63add3aede91ed2e926056305d05a1c0b53fd --- /dev/null +++ "b/C/\345\212\250\346\200\201\345\210\206\351\205\215\345\206\205\345\255\230\345\220\216\347\232\204\345\255\227\347\254\246\344\270\262\346\213\267\350\264\235\345\244\247\345\235\221.c" @@ -0,0 +1,27 @@ +#include +#include +#include + +int main() { + char *source = "Hello, World!"; + char *destination; + + // 动态分配足够的空间来存储 source 字符串 + destination = (char *)malloc(strlen(source) + 1); + + if (destination == NULL) { + fprintf(stderr, "Memory allocation failed\n"); + return 1; + } + + // 拷贝字符串 + strcpy(destination, source); + + printf("Source: %s\n", source); + printf("Destination: %s\n", destination); + + // 释放内存 + free(destination); + + return 0; +} \ No newline at end of file