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

#include <iostream>
using namespace std;
void  StrCpy(char **pDestination, char *pSource);
struct People
{
	People()
	{
		nAge = 0;
	}
	int nAge;
 
};
void main()
{
 
	
	char *pString;
	StrCpy(&pString, "fsfsafsadfsadfsadfsadfsdfsadfsadf");
	cout << pString << endl;
	int tem;
	cin >> tem;
 
 
 
}
 
 
 
void  StrCpy(char **pDestination, char *pSource)
{
 
	//cout << "OK" << endl;
	char *pResult;
	int i= 0;
	int len = 0;
	while(pSource[i]!='\0')
	{ 
		i++;
		len++;
	}
 
	*pDestination = new char[len + 1];
	pResult = *pDestination;
	int j = len - 1;
	while(j >= 0)
	{
		**pDestination = pSource[j];
		++(*pDestination);
		j--;
	}
	**pDestination = '\0';
	*pDestination = *pDestination - len;

}
 
posted @ 2013-06-24 19:13  Predator  阅读(478)  评论(0编辑  收藏  举报