strcpy是C语言中的一个字符串操作函数,用于将一个字符串复制到另一个字符串中。其函数原型为:

char *strcpy(char *dest, const char *src);

其中,dest为目标字符串的指针,src为源字符串的指针。函数将src指向的字符串复制到dest指向的字符串中,并返回dest指针。

需要注意的是,dest指向的字符串必须有足够的空间来存储src指向的字符串,否则可能会导致内存溢出。另外,src指向的字符串必须以空字符'\0'结尾,否则可能会导致字符串复制不完整。

示例代码:

#include <stdio.h>
#include <string.h>

int main() {
    char src[] = "hello world";
    char dest[20];
    strcpy(dest, src);
    printf("src: %s\n", src);
    printf("dest: %s\n", dest);
    return 0;
}

输出结果为:

src: hello world
dest: hello world
``
C语言strcpy

原文地址: https://www.cveoy.top/t/topic/gfK8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录