实现一个函数,使用指针连接两个字符串

函数输入: 两个源字符串的指针,目的字符串的指针。
在这里插入图片描述

#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>

using namespace std;

char *str(char *p1, char *p2){
	char *p = p1; 
	while (*p1++); 
	p1--; 
	while (*p1++ = *p2++); 
	return p; 
}

int main(void) {
	
	char s1[100] = "我爱", s2[100] = "编程";
	printf("拼接后的字符串为:");
	printf("%s\n", str(s1, s2)); 

	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/ZengYong12138/article/details/106491485