码迷,mamicode.com
首页 > 其他好文 > 详细

mystrcat

时间:2019-06-12 00:54:29      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:std   strlen   style   main   char*   turn   while   span   int   

#include<stdio.h>
//如果一个数组做为函数的形参传递,那么数组可以在被调用的函数中修改
//有时候不希望这个事发生,所以对形参采用const参数
//size_t strlen(const char *s);
//strcpy(char* s1,const char* s2); 
void mystrcat(char *s1,const char *s2)
{
    int len = 0;
    while(s2[len])
    {
        len++;
    }
    while(*s1)
    {
        s1++;
    }
    int i;
    for(i = 0; i < len; i++)
    {
        *s1 = *s2;
        s1++;
        s2++;
    }
}

int main()
{
    char s1[10] = "123";
    char s2[10] = "456";
    mystrcat(s1,s2);
    printf("s1 = %s\n",s1);
    return 0;
} 

 

mystrcat

标签:std   strlen   style   main   char*   turn   while   span   int   

原文地址:https://www.cnblogs.com/wanghao-boke/p/11006984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!