strcpy函数的作用是什么呀?

strcpy,即string copy(字符串复制)的缩写,是一种C语言的标准库函数。

strcpy函数的作用:对字符串进行复制(拷贝),把含有“\0”结束符的字符串复制到另一个地址空间,返回值的类型为“char*”。

在C语言函数中:

1.png-600

头文件:

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

原型声明:

char* strcpy(char* strDestination, const char* strSource);
  • 参数说明:

  • strDestination:目的字符串。

  • strSource:源字符串。

strcpy() 会把 strSource 指向的字符串复制到 strDestination。

必须保证 strDestination 足够大,能够容纳下 strSource,否则会导致溢出错误。

返回值:目的字符串,也即 strDestination。

示例:使用C语言 strcpy() 函数将字符串 src 复制到 dest。

#include <stdio.h>
#include <string.h>
int main(){
    char dest[50] = { 0 };
    char src[50] = { "http://c.0133.cn" };
    strcpy(dest, src);
    puts(dest);
    return 0;
}

运行结果:

http://c.0133.cn

更多web开发知识,请查阅 HTML中文网 !!

以上就是strcpy函数的作用是什么呀?的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 其他答疑