C language uses pointers to realize the function of strcat

Use pointer function to realize the function of string concatenation function

#include<stdio.h>
char *f(char *dst,char *src)
{
    
    
	char *q,*p;
	for(p=dst;*p;p++);
	for(q=src;*q;q++,p++)
		*p = *q;
	*p = '\0';
	return dst;
}
int main()
{
    
    
	char a[20]="abc",b[10]="def";
	printf("原字符串a: %s\n",a);
	printf("原字符串b: %s\n",b);
	printf("这是连接后的字符串: %s\n",f(a,b));
	printf("puts输出字符串: ");
 	puts(f(a,b));
 	return 0;
 }

Please correct me:)

Guess you like

Origin blog.csdn.net/qq_51311937/article/details/112213142