[cpp] view plaincopyprint?
#include <stdio.h>
#include <string.h>
#include <assert.h>
char *my_strcpy(char *dest,char *sour)
{
char *ret=dest;
assert(dest);
assert(sour);
while((*ret++ = *sour++) != '\0') //若在sour前遗漏*则会出错;因它是将sour所指向的内容赋予*ret
{
NULL;
}
dest='\0';
return ret;
}
int main()
{
char string[10]="as";
char *str1 = "abcdef";
char *p;
p = my_strcpy(string, str1);
printf("%s\n", string);
return 0;
}