不使用库函数strcat(),自行编程实现str_append()功能

来源:互联网 发布:好莱坞爱情电影知乎 编辑:程序博客网 时间:2024/06/07 00:48

不使用库函数strcat(),自行编程实现str_append()功能:已知两个字符串,将这两个字符串拼接起来作为返回值。例如函数输入参数为“Hello”和"World",那么返回值就是"HelloWorld";

#include <stdio.h>#include <string.h>char str_append(char s[],char t[]){int i,j;i=j=0;while(s[i]!='\0')i++;   while((s[i++]=t[j++])!='\0');} main() { char s[]="hello"; char t[]="world"; str_append(s,t); printf("%s",s); }


 


 

0 0