C++ C++字符串复制函数StrCpy算法设计(四)

#include <iostream>
using namespace std;
void  StrCpy(char **pDestination, char *pSource);
void main()
{	
	char *pString = NULL;
	StrCpy(&pString, "ganquanfu");
	cout << pString << endl;
	delete pString;
	pString = NULL;
 
	char *pTest = NULL;
	StrCpy(&pTest, "ASFASDFWFWQFRRQWERFEQWFSAFSdfasdfsafsafsdafssdfsadfsfsdfsdfdssfsadfsadfsdfsf");
	cout << pTest << endl;
	delete pTest;
	pTest = NULL;
	int tem;
	cin >> tem;
}
 
 
 
void  StrCpy(char **pDestination, char *pSource)
{
	char *pResult;
	int i= 0;
	int len = 0;
	while(pSource[i]!='\0')
	{ 
		i++;
		len++;
	}
 
	*pDestination = new char[len + 1];
	pResult = *pDestination;
	int j = 0;
	while(j < len)
	{
		**pDestination = pSource[j];
		++(*pDestination);
		++j;
	}
	**pDestination = '\0';
	*pDestination = *pDestination - len;
	
	
}
 
posted @ 2013-06-24 19:43  Predator  阅读(225)  评论(0编辑  收藏  举报