analyze
Strcat String concatenation function
Implement char * my_strcat(char * str1, const char * str2) function
to return the address of str1 string.
Append the string pointed to by str2 to the string pointed to by str1. The
code is as follows
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
char * my_strcat( char* str1,const char* str2)
{
char *ret = str1;
assert(str1!=NULL);
assert(str2!=NULL);
while(*str1!='\0')//让指针指向str1的最后面
{
str1++;
}
while(*str1++ = *str2++)
{
;
}
return ret;
}
test section
int main()
{
char arr1[10]="hello ";
char arr2[]="word";
my_strcat(arr1,arr2);
printf("%s",arr1);
system("pause");
return 0;
}
operation result