C语言用指针实现strcat函数功能

用指针函数实现字符串连接函数功能

#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;
 }

欢迎指正 : )

猜你喜欢

转载自blog.csdn.net/qq_51311937/article/details/112213142