<五> strcpy函数

strcpy函数

char *strcpy(char *dest, const char *src);
功能:将后面的字符串拷贝到前边
参数:char*传递地址
返回:返回dest
注意:dest的空间足够大,dest不能传递常量的地址

地址:数组名 字符串常量
const:可以传递常量的地址、变量的地址

数组在越界访问时不会报错!!!

 1 #include <stdio.h>
 2 #include <string.h>  //strcpy函数需要一个string.h的头文件
 3 
 4 int main(int argc, const char *argv[])
 5 {
 6     char a[32] = "helloworld";
 7     char b[] = "bei";
 8     int i = 0;
 9 
10     while(b[i] != '\0')
11     {
12         a[i] = b[i];
13         i++;
14     }
15     a[i] = '\0';
16     printf("a = %s\n",a);
17 
18         //以上是用c对此函数的实现
19         //此函数的实现如下
20         //strcpy(a,b);
21         //printf("a=%s\n",a);
22         //printf("a=%s\n",strcpy(a,"beijing"));
23 
24 
25     return 0;
26 }

 

posted on 2018-03-10 20:07  就是菁可爱哦  阅读(196)  评论(0编辑  收藏  举报

导航