Home C&C++函数库 c++ 语法 程序源码 Linux C库

strcpy

函数   <cstring>

char * strcpy ( char * destination, const char * source );

字符串拷贝

将源(source )指向的C字符串复制到目标(destination)指向的数组中,包括终止空字符(并在此处停止)。

为了避免溢出,destination指向的数组的大小应该足够长,以包含与source相同的C字符串 (包括结束的null字符),并且不应该在内存中与source重叠。

☲  参数


destination
指向要复制内容的目标数组的指针。

source
要复制的C字符串。

☉  返回值



返回 destination 。

☣  示例



/* strcpy example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str1[]="Sample string";
  char str2[40];
  char str3[40];
  strcpy (str2,str1);
  strcpy (str3,"copy successful");
  printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3);
  return 0;
}

输出:
str1: Sample string
str2: Sample string
str3: copy successful

🍄  另请参阅



memcpy 拷贝内存块(function)
strncpy 从字符串复制字符(function)
memchr 在内存块中定位字符(function)
memcmp 比较两个内存块(function)
memset 填充内存块(function)
memmove 移动内存块(function)

联系我们 免责声明 关于CandCplus 网站地图