From 163a6354bfce85f711808d40d7b3ca76c25bae34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E9=87=91=E9=9B=B7?= <135652820@qq.com> Date: Fri, 1 Nov 2024 09:08:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=88=86=E9=85=8D=E5=86=85?= =?UTF-8?q?=E5=AD=98=E5=90=8E=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=8B=B7?= =?UTF-8?q?=E8=B4=9D=E5=A4=A7=E5=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...267\350\264\235\345\244\247\345\235\221.c" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "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" 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 0000000..40a63ad --- /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 -- Gitee