c语言用strdel函数,字符串函数(strcpy字符串拷,strcmp字符串比较,strstr字符串查找,strDelChar字符串删除字符,strrev字符串反序,memmove拷贝内存块,str...

1.strcpy字符串拷贝

拷贝pStrSource到pStrDest,并返回pStrDest地址(源和目标位置重叠情况除外)

a6faaec4e76614e82527ee49d9cc76ca.gif

char *strcpy(char *pStrDest, const char *pStrSource)

{

assert(NULL!=pStrDest && NULL!=pStrSource);

char *strTemp=pStrDest;

while ((*pStrDest++ = *pStrSource++) != '\0');

return strTemp;

}

fc0011bf47a84db1c4cd9c98160b31c5.gif

2.strcmp字符串比较

3273bacd90ed4b38458ccd062760a34d.gif

int strcmp(const char *pStrA, const char *pStrB)

{

assert(NULL!=pStrA && NULL!=pStrB);

while (*pStrA && *pStrB && *pStrA==*pStrB)

{

++pStrA;

++pStrB;

}

return (pStrA-*pStrB);

}

82ab36da4dae8e409e0460799a99b9f3.gif

3.strstr字符串查找

adb8673bf5979731b9b6541c5179e328.gif

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;

}

1ab4033b291744c58865fe53cd149d0c.gif

4.strDelChar字符串删除字符

0eeb8ef6ab38ba13a4545ef67950c5f9.gif

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;

}

a0641257e2b6a643084214f5a31eddae.gif

5.strrev字符串反序

7dd064322cf586540e922a6caa16ded5.gif

char *strrev(char *pStrSource)

{

assert (NULL != pStrSource);

char *pStrStart, *pStrEnd;

pStrStart = pStrEnd = pStrSource;

while (*pStrEnd != '\0')

{

++pStrEnd;

}

char chTemp;

for (--pStrEnd, pStrStart; pStrEnd

{

chTemp = *pStrStart;

*pStrStart = *pStrEnd;

*pStrEnd = chTemp;

}

return pStrSource;

}

bb7c20c390f0a254b7ac67ebaba3867d.gif

6.memmove拷贝内存块

da594445213ca4b4cc22c495e786a09a.gif

void *memmove(void *pStrTo, const void *pStrFrom, size_t count)

{

assert (NULL!=pStrTo && NULL!=pStrFrom);

void *pStrRet = pStrTo;

if (pStrTopStrFrom+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;

}

39f91f49735e93915712af4cb1ccd7f2.gif

7.strlen字符串长度

699f40f6061c290fff3b0e1559838794.gif

int strlen(const char *pStrSource)

{

assert(NULL != pStrSource);

int iLen = 0;

while (*pStrSource++ != '\0')

{

++iLen;

}

return iLen;

}

2f338c089b68395bc13b22dea6c2fd51.gif

http://www.cnblogs.com/sz-leez/p/4531507.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值