本文主要是介绍C语言-strlen/memcpy/strcpy,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
strlen不使用任何变量实现
int FunStrlen(const char *strDest)
{if(NULL == strDest){printf("NULL == strDest, return!\n");return -1;}if('\0' == *strDest){return 0;}else{return (1+FunStrlen(++strDest));}
}
return *strDest ? 1+FunStrlen(++strDest) : 0;
return ('\0' != *strDest) ? 1+FunStrlen(++strDest) : 0;
memcpy
void *FunMemcpy(void *dest, const void *src, size_t n)
{char *tmp=dest;const char *s=src;if(NULL==dest || NULL == src){return;}while(n--){*tmp++ = *s++;}return dest;
}
strcpy
char *FunStrcpy(char *dest, const char *src)
{char *tmp=dest;const char *s=src;if(NULL==dest || NULL == src){return NULL;}while('\0' != *s){*tmp++ = *s++;}return dest;
}
这篇关于C语言-strlen/memcpy/strcpy的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!