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

#include <iostream>
using namespace std;
void ChangeArray(int p[]);
char * StrCpy(char *pSource);

void main()
{
 int datas[4]={ 1, 2, 3, 4};
 ChangeArray(datas);
 for(int i =0; i<4; i++)
 {
  cout << datas[i] << endl;//数值已经改变即datas[0] = 10;
 }

 char *pString = NULL;
 pString = StrCpy("fsfsafsadfsadfsadfsadfsdfsadfsadf");
 cout << pString << endl;
 int tem;
  cin >> tem;

 

}


char * StrCpy(char *pSource)
{
 int i= 0;
 int len = 0;
 while(pSource[i]!='\0')
 { 
  i++;
  len++;
 }

 char *pDestination = new char[len + 1];
 int j = len - 1;
 while(j >= 0)
 {
  pDestination[j] = pSource[j];
  j--;
 }
 pDestination[len] = '\0';
 return pDestination;

}


void ChangeArray(int p[])
{
 p[0] = 10;
}

posted @ 2013-06-12 14:46  Predator  阅读(266)  评论(0编辑  收藏  举报