strcpy实现

#include <iostream>
using namespace std;
char *strcpy(char *strDest, const char *strSrc)
{
	if ( strDest == NULL || strSrc == NULL)
		return NULL ;
	if ( strDest == strSrc)
		return strDest ;
	char *tempptr = strDest ;
	while((*strDest++ = *strSrc++) != '');
	return tempptr ;
}

int main()
{
	char strA[20]="ABCDEFGHIJKLMNOPQRS";
	char* strB="how are you ?";
	int length=strlen(strcpy(strA,strB));
	//int lh=strlen(strncpy(strA,strB,sizeof(strA)));
	//printf("%s",strA);
	cout<<length<<endl;
	/*cout<<lh<<endl;*/
	//char a[30] = "string(1)";
	//char b[] = "string(2)";
	//printf("before strncpy() : %s
", a);
	//printf("after strncpy() : %s
", strncpy(a, b, 8));
	while(1);
	return 0;
}

  

原文地址:https://www.cnblogs.com/wuyuankun/p/3684718.html