字符串函数(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 ...
随机推荐
- POJ 1442 Black Box treap求区间第k大
题目来源:POJ 1442 Black Box 题意:输入xi 输出前xi个数的第i大的数 思路:试了下自己的treap模版 #include <cstdio> #include < ...
- 36.Node.js 工具模块--OS模块系统操作
转自:http://www.runoob.com/nodejs/nodejs-module-system.html Node.js os 模块提供了一些基本的系统操作函数.我们可以通过以下方式引入该模 ...
- 1.23 Python知识进阶 - 面向对象编程
一.编程方法 1.函数式编程:"函数式编程"是一种"编程范式"(programming paradigm),也就是如何编写程序的方法论.它属于"结构化 ...
- 洛谷P3403跳楼机(最短路构造/同余最短路)
题目-> 解题思路: 最短路构造很神啊. 先用前两个值跑在第三个值模意义下的同余最短路(这步贪心可以证明,如果第三步长为z,那么如果n+z可以达到,n+2z同样可以达到) 最后计算与楼顶差多少个 ...
- HDU 1506 Largest Rectangle in a Histogram(DP)
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- web service 原理
Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的 ...
- 关于数据库中的JOIN的用法学习
下面是例子分析 表A记录如下: aID aNum 1 a20050111 2 a20050112 3 a20050113 4 a20050114 5 a20050115 表B记录如下: ...
- Python图片的横坐标汉字
给一个例子 : # -*- coding: utf-8 -*-import matplotlib.pyplot as plt import py_hanzi as ch #关键在于这 ...
- 【CS Round #43 E】Coprime Pairs
[链接]点击打开链接 [题意] 让你选择n个数字,组成一个数组,使得这n个数字中恰好有k对,它们是互质的. [题解] 我们可以先找出前n个质数,那么接下来的问题就转化为,凑出rest = n*(n-1 ...
- ArcGIS教程:地理处理服务演示样例(河流网络)(三)
设置输出符号系统 步骤: 展开 StoweStreamNet.tbx 并双击创建河流网络模型. 接受默认的 45 公顷并单击确定以运行模型. StreamNet 图层将加入至 ArcMap. 右键单击 ...