strcat
3、strcat 复制连接
strcat将str2的字符串复制到str1的尾端,不覆盖str1进行复制,
using namespace std;
#include<iOStream>
#include<assert.h>
char* mystrcat(char* dest, const char* src){
char* ptr = dest;
assert(dest&&src);
while (*dest){
dest++;
}
while (*dest = *src){
dest++;
src++;
}
return (char*) ptr;
}
int main(){
char arr1[] = "Hello";
char arr2[] = " World";
char* ret=mystrcat(arr1,arr2);
printf("复制后字符串: %s\n ",ret);
system("pause");
return 0;
}
结果:
相关阅读
函数原型:char* strcat (char*, const char*); char *my_str_cat(char* p_des, const char* p_src) { if (NULL ==
1 strcpy原型声明:extern char *strcpy(char* dest, const char *src);头文件:#include <string.h>功能:把从src地址开始且含有NULL