编写一个程序,将字符数组s2中的全部字符复制到字符数组s1中...

#include <stdio.h>
#include <windows.h>
/*
	不用 strcpy 实现将一个字符串复制到另一个字符串中
	*/
//写一个这样的函数
void Strcpy(char* s1, const char* s2) {
	while (*s2 != '\0') {
		*s1++ = *s2++;
	}
	*s1 = *s2; //把 '\0' 也要复制进去
}

int main() {
	char s1[1024] = "sock";
	char s2[1024] = "jiesi";
	Strcpy(s1, s2);
	printf("%s\n", s1);

	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42957923/article/details/84846689