功能:比较两个字符串的ascII码大小

输入:两个字符串

返回值:相等为0,大于为大于零,小于为小于零

#include <iostream>
#include <assert.h>
using namespace std;
int _strcmp(const char *str1,const char *str2)
{
assert((str1 != NULL)&&(str2 != NULL));
while (*str1 && *str2 && *str1 == *str2)
{
str1++;
str2++;
}
return *str1- *str2;
}
int main()
{
const char *str1 = "abcdef";
const char *str2 = "aBe";
cout << _strcmp(str1,str2)<<endl;
return 0;
};

字符串之strcmp的更多相关文章

  1. 内置函数 字符串比较 strcmp 登录密码

    1 //内置函数 字符串比较 strcmp 2 // 原理:将两个字符串从首字母开始,按照ASCII码的顺序逐个比较 3 //字符串1 == 字符串2 返回0 4 //字符串1 < 字符串2, ...

  2. c语言字符串比较函数strcmp

    strcmp(s1,s2) 说明: 当s1<s2时,返回值<0 当s1=s2时,返回值=0 当s1>s2时,返回值>0两个字符串自左向右逐个字符相比(按ASCII值大小相比较) ...

  3. 字符串比较strcmp

    问题: 原型:extern int strcmp(const char *s1,const char * s2); 所在头文件:string.h 功能:比较字符串s1和s2. 一般形式:strcmp( ...

  4. 字符串函数---strcmp()与strncmp()具体解释及实现

    一.strcmp()与strncmp() strcmp():strcmp(s1,s2);            比較两个字符串.        strncmp():strncmp(s1,s2);   ...

  5. 字符串函数---strcmp()与strncmp()详解及实现【转】

    本文转载自:http://blog.csdn.net/lanzhihui_10086/article/details/39829623 一.strcmp()与strncmp() strcmp():st ...

  6. PHP 语法字符串函数 strcmp、strlen 使用及实现

    说明 这里基于 php7.2.5 进行测试,php7 之后内部结构变化应该不是太大,但与 php5.X 有差别. 函数分类 用户自定义函数 say(); function say() { echo & ...

  7. 嵌入式-C语言基础:字符串比较函数strcmp及其实现

    #include<stdio.h> #include <string.h> int mystrcmp(char * p1,char * p2) { int ret=0; if( ...

  8. php中常用的字符串比较函数strcmp()实例解释

    int strcmp ( string $str1 , string $str2 ) 以二进制方式进行比较以该函数比较时区分大小写返回值,如果str1小于str2返回<0,如果str1大于str ...

  9. Strcmp(字符串1,字符串2)函数 Sizeof && strlen() Substr(a,b)

    Strcmp(字符串1,字符串2)函数 { strcmp函数是比较两个字符串的大小,返回比较的结果.一般形式是:  i=strcmp(字符串,字符串); 其中,字符串1.字符串2均可为字符串常量或变量 ...

随机推荐

  1. Vue 获取验证码倒计时组件

    子组件 <template> <a class="getvalidate":class="{gray: (!stop)}"@click='cl ...

  2. php画图应用之验证码

    在画图里面,就像之前所说的.php的画图是真正动态画图,尽管自己承认会出的图是非常不好看的.但我们主要关注的应该还是数据处理. 验证码我们差点儿无处不见,它的产生和画图技术是密不可分的.事实上,简单的 ...

  3. 2. Add Two Numbers【medium】

    2. Add Two Numbers[medium] You are given two non-empty linked lists representing two non-negative in ...

  4. java代码格式化

    Java source formatting You are probably familiar with the Eclipse hotkeys to automatically format yo ...

  5. LINUX内核升级-更新网卡驱动

    因项目需要,将当前内核(2.6.32-220.el6.x86_64)升级到目标内核(2.6.33-110.el6.x86_64),但是编译的目标 内核(2.6.33-110.el6.x86_64)的对 ...

  6. CodeIgniter 框架在Apache服务器下去掉index.php 总结

    最近一段时间一直研究CI框架,但是对CI框架的跳转链接一直需要加index.php前缀,经过CI论坛的各种解决方案,最后总结记录一下自己实际操作去掉index.php的过程. 1.要修改Apache ...

  7. Java正则表达式之Matcher类的find和matches方法的区别

    讨论整个问题之前,先看个例子:   从上面的例子可以看出 matches()是整个字符串完全匹配时,才会返回true 而find()则只需要字符串中,找到某部分的子字符串匹配则返回true       ...

  8. jQuery 和其他 JavaScript 框架

    正如您已经了解到的,jQuery 使用 $ 符号作为 jQuery 的简写. 如果其他 JavaScript 框架也使用 $ 符号作为简写怎么办? 其他一些 JavaScript 框架包括:MooTo ...

  9. iframe详解

    如何查看是否为iframe *使用FireFox组件firebug->firepath 1.Top Window:可直接定位 2.iframe#i:根据id定位 定位方法: switch_to. ...

  10. php读取xml的神器

    <?xml version="1.0 encoding="UTF-8"?> <humans> <zhangying> <name ...