自己动手写字符串比较函数strcmp()
来源:互联网 发布:python post json 编辑:程序博客网 时间:2024/06/05 01:08
最近用到了字符串比较的函数,用到strcmp函数。除了知道怎么用之外,我觉得有必要把它的源码搞一搞。
搜到网上流传的strcmp函数的源码是如下:
int strcmp (const char * src, const char * dst){ int ret = 0 ; while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst) ++src, ++dst; if ( ret < 0 ) ret = -1 ; else if ( ret > 0 ) ret = 1 ; return( ret );}其中的unsigned char *不是很好理解,先放一放,等有时间再理解一下。下面附上我的代码
int mystrcmp(const char * src, const char *des){if(!src || !des) rerurn src-des;while(*src && (*src == *des)){ ++src; ++des;}return *src-*des;}
0 0
- 自己动手写字符串比较函数strcmp()
- 字符串比较函数strcmp
- 比较字符串strcmp()函数
- strcmp字符串比较函数
- strcmp()字符串比较函数
- 编写字符串比较函数strcmp
- 编写字符串比较函数strcmp .
- strcmp()字符串比较函数
- 完成字符串比较函数strcmp()
- 写一函数,实现两个字符串的比较,即自己写一个strcmp函数
- P279_1017 写一函数,实现两个字符串的比较,即自己写一个strcmp函数
- 【字符串比较函数】strcmp,stricmp,strcmpi区别
- strcmp()字符串比较函数用法问题
- 实现strcmp函数功能--比较字符串
- 指针实现字符串比较函数strcmp
- strcmp和memcmp两个字符串比较函数
- 字符串比较用strcmp
- 比较字符串大小strcmp
- Android 使用开源库StickyGridHeaders来实现带sections和headers的GridView显示本地图片效果
- CSS样式字体设置失效,呈现乱码
- Another MySQL daemon already running with the same unix socket.
- Arrays of pointers to functions
- C++ 经典开源代码
- 自己动手写字符串比较函数strcmp()
- http状态码
- 设计模式C++实现(1)——工厂模式(Factory)
- Linux NAPI机制
- rpm命令详解及安装
- 读背包九讲心得
- iOS多线程开发---线程同步
- Alamofire-Swift Networking网络库
- 点击确定让dialog不消失