字符串函数(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语言-字符串函数的实现(五)之strstr
C语言中的字符串函数有如下这些 获取字符串长度 strlen 长度不受限制的字符串函数 strcpy strcat strcmp 长度受限制的字符串函数 strncpy strncat strncmp ...
- C/C++ 知识点---字符串函数
1.strcpy字符串拷贝2.strcmp字符串比较3.strstr字符串查找4.strDelChar字符串删除字符5.strrev字符串反序6.memmove拷贝内存块7.strlen字符串长度 - ...
- C语言-字符串函数的实现(二)之strcpy
C语言中的字符串函数有如下这些 获取字符串长度 strlen 长度不受限制的字符串函数 strcpy strcat strcmp 长度受限制的字符串函数 strncpy strncat strncmp ...
- 【Linux C中文函数手册】之 内存和字符串函数
内存和字符串函数 1) bcmp 比较内存内容 相关函数 bcmp,strcasecmp,strcmp,strcoll,strncmp,strncasecmp表头文件 #include<stri ...
- C语言-字符串函数的实现(一)之strlen
C语言中的字符串函数有如下这些 获取字符串长度 strlen 长度不受限制的字符串函数 strcpy strcat strcmp 长度受限制的字符串函数 strncpy strncat strncmp ...
- 字符串函数的实现(三)之strcat
C语言中的字符串函数有如下这些 获取字符串长度 strlen 长度不受限制的字符串函数 strcpy strcat strcmp 长度受限制的字符串函数 strncpy strncat strncmp ...
- Python3中的字符串函数学习总结
这篇文章主要介绍了Python3中的字符串函数学习总结,本文讲解了格式化类方法.查找 & 替换类方法.拆分 & 组合类方法等内容,需要的朋友可以参考下. Sequence Types ...
- c#编程基础之字符串函数
c#常用的字符串函数 例一: 获取字符串的大小写函数 ToLower():得到字符串的小写形式 ToUpper():得到字符串的大写形式 注意: 字符串时不可变的,所以这些函数都不会直接改变字符串的内 ...
- awk字符串函数及其意义
awk字符串函数及其意义 awk提供了强大的内置字符串函数,用于实现文本的字符串替换.查找以及分隔等功能. awk字符串函数主要有:gsub.index.length.match.split.sub ...
随机推荐
- Codeforces Round #316 (Div. 2) A B C
A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- 例说linux内核与应用数据通信(四):映射设备内核空间到用户态
[版权声明:尊重原创,转载请保留出处:blog.csdn.net/shallnet.文章仅供学习交流,请勿用于商业用途] 一个进程的内存映象由以下几部分组成:代码段.数据段.BSS段和 ...
- holder.js如何使用
holder.js的使用 一.总结 一句话总结:使用:holder.js后面接图片宽高 <img src="holder.js/300x200" /> 1.holder ...
- zenDiscovery和master选举
上一篇通过 ElectMasterService源码,分析了master选举的原理的大部分内容:master候选节点ID排序保证选举一致性及通过设置最小可见候选节点数目避免brain split.节点 ...
- 2.Xml与多个对象的映射(聚合或组合)及注意事项
在我们的实际应用中,Xml中的结构往往不止这么简单,一般都会有2,3层.也就是说如果映射成对象就是聚合(组合)的情况 . 就用我们上一章的例子继续来讲,简单我们的Book的author现在不止是一个S ...
- scrapy爬取知乎某个问题下的所有图片
前言: 1.仅仅是想下载图片,别人上传的图片也是没有版权的,下载来可以自己欣赏做手机背景但不商用 2.由于爬虫周期的问题,这个代码写于2019.02.13 1.关于知乎爬虫 网上能访问到的理论上都能爬 ...
- 洛谷——P1781 宇宙总统
https://www.luogu.org/problem/show?pid=1781 题目背景 宇宙总统竞选 题目描述 地球历公元6036年,全宇宙准备竞选一个最贤能的人当总统,共有n个非凡拔尖的人 ...
- Http请求连接池 - HttpClient 的 PoolingHttpClientConnectionManager
两个主机建立连接的过程是非常复杂的一个过程,涉及到多个数据包的交换,而且也非常耗时间.Http连接须要的三次握手开销非常大,这一开销对于比較小的http消息来说更大.但是假设我们直接使用已经建立好的h ...
- 26.SpringBoot事务注解详解
转自:https://www.cnblogs.com/kesimin/p/9546225.html @Transactional spring 事务注解 1.简单开启事务管理 @EnableTrans ...
- java 文件读写--转载
读文件 http://www.baeldung.com/java-read-file Java – Read from File 1. Overview In this tutorial we’ll ...