实现几个字符串常用函数
来源:互联网 发布:php面试自我介绍 编辑:程序博客网 时间:2024/04/30 09:22
实现几个字符串常用函数,练习一下写代码。经常谢谢代码,使自己不要忘了如何写代码。
字符比较函数
字符串赋值函数
求字符串长度
字符串那倒置
字符串比较
字符串连接
// string.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <assert.h>#include "string.h"//字符交换函数void charswap(char& ch1, char& ch2){char ch = ch1;ch1 = ch2;ch2 = ch;}//求字符串长度int stringlength(const char* sourstr){const char *pstr = sourstr;int length = 0;while(*pstr++ != '\0'){length++;}return length;}//字符串那倒置char* stringconvert(char* sourstr){int length = stringlength(sourstr);int loopnumber = length / 2;int index = 0;while(index < loopnumber){charswap(*(sourstr + index), *(sourstr + length - index - 1));index++;}return sourstr;}//字符串复制char* stringcopy(char* deststr, const char* sourstr){const char* pstr = sourstr;int index = 0;while(*pstr != '\0'){*(deststr + index) = *pstr++;index++;}*(deststr + index) = '\0';return deststr;}//字符串连接char* stringcontact(char* deststr, const char* sourstr){const char* pstr = sourstr;int length = stringlength(deststr);int index = 0;while(*pstr != '\0'){*(deststr + length + index) = *pstr++;index++;}*(deststr + length + index ) = '\0';return deststr;}//字符串比较函数int stringcompare(const char* deststr, const char* sourstr){const char* pdest = deststr;const char* psour = sourstr;while(*pdest == *psour && *pdest != '\0'){pdest++;psour++;}return *pdest - *psour;}int main(int argc, char* argv[]){ char buff1[100];char buff2[100];stringcopy(buff1, "reqre12345");stringcopy(buff2, "reqre1");printf("%d\n", stringcompare(buff1, buff2));getchar();return 0;}
- 实现几个字符串常用函数
- 字符串的几个常用函数的C实现
- 常用的几个字符串函数的使用和实现
- C#字符串几个常用函数
- 几个字符串函数的实现
- 几个字符串函数的实现
- 常用字符串函数实现
- 字符串常用函数实现
- 字符串处理的几个常用函数
- 几个常用的js字符串处理函数
- js 的几个常用的字符串函数
- C语言字符串几个常用函数小结
- 常用的几个字符串Hash函数
- 收藏 C#字符串几个常用函数
- java中几个常用的字符串函数
- C语言字符串几个常用函数
- 编写关于字符串的几个常用函数
- 几个常见字符串函数的实现
- 程序崩溃时打印调用栈
- 黑马程序员—Java提高2(泛型,内省)
- 10个你必须掌握的超酷VI命令技巧
- Cauchy-Schwarz不等式的证明
- 初识block
- 实现几个字符串常用函数
- MySQL学习足迹记录07--数据过滤--用正则表达式进行检索
- 图像几何变换之图像位置变换之图像旋转
- linux路由内核实现分析(四)---路由缓存机制(1)
- linux路由内核实现分析(四)---路由缓存机制(2)
- oracle中distinct的正确应用
- linux路由内核实现分析(四)---路由缓存机制(3)
- [转]浏览器的渲染原理简介
- linux路由内核实现分析(四)---路由缓存机制(4)