字符串函数(strcpy字符串拷,strcmp字符串比较,strstr字符串查找,strDelChar字符串删除字符,strrev字符串反序,memmove拷贝内存块,strlen字符串长度)(示例代
Posted 朝闻道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串函数(strcpy字符串拷,strcmp字符串比较,strstr字符串查找,strDelChar字符串删除字符,strrev字符串反序,memmove拷贝内存块,strlen字符串长度)(示例代相关的知识,希望对你有一定的参考价值。
1.strcpy字符串拷贝
拷贝pStrSource到pStrDest,并返回pStrDest地址(源和目标位置重叠情况除外)
char *strcpy(char *pStrDest, const char *pStrSource) { assert(NULL!=pStrDest && NULL!=pStrSource); char *strTemp=pStrDest; while ((*pStrDest++ = *pStrSource++) != \'\\0\'); return strTemp; }
2.strcmp字符串比较
int strcmp(const char *pStrA, const char *pStrB) { assert(NULL!=pStrA && NULL!=pStrB); while (*pStrA && *pStrB && *pStrA==*pStrB) { ++pStrA; ++pStrB; } return (pStrA-*pStrB); }
3.strstr字符串查找
char *strstr(const char *pStrSource, const char *pStrSearch) { assert(pStrSource != NULL && pStrSearch != NULL); const char *strTempSource = pStrSource; const char *strTempSearch = pStrSearch; for (; *pStrSource!=\'\\0\'; ++pStrSource) { for (strTempSource=pStrSource,strTempSearch=pStrSearch; *strTempSearch!=\'\\0\' && *strTempSearch==*strTempSource; ++strTempSource, ++strTempSearch); if (*strTempSearch == \'\\0\') { return (char *)pStrSource; } } return (char *)NULL; }
4.strDelChar字符串删除字符
char *strDelChar(char *pStrSource, const char chDel) { assert(NULL!=pStrSource && !isspace(chDel)); char *pTempStrA, *pTempStrB; pTempStrA = pTempStrB = pStrSource; while (*pTempStrB++) { if (*pTempStrB != chDel) { *pTempStrA++ = *pTempStrB; } } *pTempStrA = \'\\0\'; return pStrSource; }
5.strrev字符串反序
char *strrev(char *pStrSource) { assert (NULL != pStrSource); char *pStrStart, *pStrEnd; pStrStart = pStrEnd = pStrSource; while (*pStrEnd != \'\\0\') { ++pStrEnd; } char chTemp; for (--pStrEnd, pStrStart; pStrEnd<pStrStart; ++pStrStart, --pStrEnd) { chTemp = *pStrStart; *pStrStart = *pStrEnd; *pStrEnd = chTemp; } return pStrSource; }
6.memmove拷贝内存块
void *memmove(void *pStrTo, const void *pStrFrom, size_t count) { assert (NULL!=pStrTo && NULL!=pStrFrom); void *pStrRet = pStrTo; if (pStrTo<pStrFrom || pStrTo>pStrFrom+count-1) { //内存块不重叠情况 while (count--) { *pStrTo++ = *pStrFrom++; } } else { //内存块重叠情况 char *pStrDest = (char *)pStrTo; char *pStrSource = (char *)pStrFrom; pStrDest = pStrDest+count-1; pStrSource = pStrSource+count-1; while (count--) { *pStrDest-- = *pStrSource--; } } return pStrRet; }
7.strlen字符串长度
int strlen(const char *pStrSource) { assert(NULL != pStrSource); int iLen = 0; while (*pStrSource++ != \'\\0\') { ++iLen; } return iLen; }
http://www.cnblogs.com/sz-leez/p/4531507.html
以上是关于字符串函数(strcpy字符串拷,strcmp字符串比较,strstr字符串查找,strDelChar字符串删除字符,strrev字符串反序,memmove拷贝内存块,strlen字符串长度)(示例代的主要内容,如果未能解决你的问题,请参考以下文章
C语言学习字符串操作函数——————>strlen strcpy strcmp 详解与手动实现
C语言学习字符串操作函数——————>strlen strcpy strcmp 详解与手动实现
C语言学习字符串操作函数——————>strlen strcpy strcmp 详解与手动实现