#include <iostream>
using namespace std;
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
char* StrCpy(char* strDest, const char* strSrc)
{
assert(strDest!=NULL && strSrc!=NULL);
char *address = strDest; // 返回值保存
while((*strDest++=*strSrc++)!='\0')
;
/*
while(*strSrc!='\0')
{
*strDest++ = *strSrc++;
}
*strDest = '\0';
*/
return address;
}
int main()
{
char *strSrc = "hello world!";
char *strDest = (char*)malloc(strlen(strSrc) + 1); //动态内存分配
//char strDest[256]; //静态内存分配
cout<<StrCpy(strDest,strSrc)<<endl;
free(strDest);
return 0;
}
using namespace std;
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
char* StrCpy(char* strDest, const char* strSrc)
{
assert(strDest!=NULL && strSrc!=NULL);
char *address = strDest; // 返回值保存
while((*strDest++=*strSrc++)!='\0')
;
/*
while(*strSrc!='\0')
{
*strDest++ = *strSrc++;
}
*strDest = '\0';
*/
return address;
}
int main()
{
char *strSrc = "hello world!";
char *strDest = (char*)malloc(strlen(strSrc) + 1); //动态内存分配
//char strDest[256]; //静态内存分配
cout<<StrCpy(strDest,strSrc)<<endl;
free(strDest);
return 0;
}