strcat(s, t)用指针完成

版权声明:原创请勿随意转载。 https://blog.csdn.net/yjysunshine/article/details/81711048

《C程序设计语言》5-3

题目:用指针方式实现第2章中的函数strcat。函数strcat(s, t)将t指向的字符串复制到s指向的字符串的尾部

#include <stdio.h>
/*strcat(s, t) 将t所指向的字符串复制到s所指字符串的尾部,用指针完成*/
void strcat(char *s, char *t);

int main()
{
    char s[10] = "yjy";
    char t[] = "girl";
    strcat(s, t);
    printf("%s\n", s);
    return 0;
}
void strcat(char *s, char *t)
{
    while(*s != '\0')
        s++;
    while(*t != '\0'){
        *s = *t;
        t++;
        s++;
    }
    *s = '\0';
}
 

猜你喜欢

转载自blog.csdn.net/yjysunshine/article/details/81711048