标签:
char* strcpy(char *strDes, char *strSrc) { if (strDes == strSrc) //判断是否相等 return strDes; assert(strDes != NULL && strSrc != NULL); //判空 char *des = strDes; //保存strDes基址 while ((*des++ = *strSrc++) != ‘\0‘) //判断结束 ; return strDes; }
字符串拷贝函数需要考虑到以下几点:
char* strncpy(char *strDes, char *strSrc, size_t n) { if (strDes == strSrc) return strDes; assert(n > 0 && strDes != NULL && strSrc != NULL); char *des = strDes; while ((*des++ = *strSrc++) != ‘\0‘ && n-- > 0) ; if (*(--des) != ‘\0‘) *des = ‘\0‘; return strDes; }
void* memcpy(void* dest, void* source, size_t count) { void* ret = dest; //copy from lower address to higher address while (count--) *dest++ = *source; return ret; }
标签:
原文地址:http://www.cnblogs.com/wuchanming/p/4341411.html