<六> strcat函数

strcat函数

char *strcat(char *dest, const char *src);
功能:将后面的字符串拼接到前面
参数:char*传递地址
返回:返回dest
注意:dest空间足够大,dest只能传递变量的地址

 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 int main(int argc, const char *argv[])
 5 {
 6     char a[32] = "hello";
 7     char b[] = "world";
 8     int i = 0,j = 0;     //i:a的下标  j:b的下标
 9 
10     while(a[i] != '\0')
11     {
12         i++;             //当结束循环是a[i] == ‘\0’  i == 5 
13     }
14 
15     while(b[j] != '\0')
16     {
17         a[i] = b[j];
18         i++;
19         j++;
20     }
21 
22     a[i] = '\0';
23     printf("a = %s\n",a);
24         //以上是用c对此函数的实现
25 
26 //    strcat(a,"beijing");
27 //    printf("a = %s\n",a);
28 //    printf("a = %s\n", strcat(a,b);
29 
30     
31     return 0;
32 } 

 

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

导航