你能够写出完整的字符串拷贝函数吗?完整的代码如下:#include stdafx.h#include iostream#include ass
你能够写出完整的字符串拷贝函数吗?
完整的代码如下:
#include "stdafx.h"
#include <iostream>
#include <assert.h>
using namespace std;
void StrCpy(char* destStr,const char* srcStr)
{
assert((srcStr!=NULL)&&(destStr!=NULL));
if (srcStr==destStr)//有重复则直接返回
{
return ;
}
char* addr=destStr;
while ((*destStr++=*srcStr++)!='\0');
}
int _tmain(int argc, _TCHAR* argv[])
{
char srcStr[]="abcd";
char destStr[]="df";
//cout<<StrCpy(dest,srcStr)<<endl;
StrCpy(destStr,srcStr);
cout<<destStr<<endl;
system("pause");
return 0;
}
#include "stdafx.h"#include <iostream>#include <assert.h>using namespace std;void StrCpy(char* destStr,const char* srcStr){assert((srcStr!=NULL)&&(destStr!=NULL));if (srcStr==destStr)//有重复则直接返回{return ;}char* addr=destStr;while ((*destStr++=*srcStr++)!='\0');}int _tmain(int argc, _TCHAR* argv[]){char srcStr[]="abcd";char destStr[]="df";//cout<<StrCpy(dest,srcStr)<<endl;StrCpy(destStr,srcStr);cout<<destStr<<endl;system("pause");return 0;}
