#include <iostream>
#include <assert.h>
using namespace std;
char *strcpy_mf(char *dst,const char *src)
{
assert((dst != NULL)&&(src != NULL));
char *temp = dst;
while(*src != '\0')
{
*dst++ = *src++;
}
*dst = '\0';
return temp;
}
void main()
{
char *s2 = "copy11";//正常
//char *s2;//运行错误
//char *s2 = "";//运行正确,输出空串
char *s1 = (char *)malloc(strlen(s2)+1);
strcpy_mf(s1,s2);
cout << s1 <<endl;
}
strcpy函数实现
最新推荐文章于 2024-05-13 17:15:39 发布