函数原型:    extern int strcmp(const char *s1,const char *s2);
比较两个字符串
设这两个字符串为str1,str2,
若str1=str2,则返回零;
若str1<str2,则返回负数;
若str1>str2,则返回正数
两个字符串自左向右逐个字符相比(按ASCII值大小相比较),直到出现不同的字符或遇'\0'为止
int strcmp(const char *str1,const char *str2)
{
/*不可用while(*str1++==*str2++)来比较,当不相等时仍会执行一次++,
return返回的比较值实际上是下一个字符。应将++放到循环体中进行。*/
while(*str1 == *str2)
{
assert((str1 != NULL) && (str2 != NULL));
if(*str1 == '\0')
return ;
str1++;
str2++;
}
return *str1 - *str2;
}

C语言strcmp()实现的更多相关文章

  1. C语言strcmp()函数:比较两个字符串

    strcmp() 函数用于对两个字符串进行比较(区分大小写). 头文件:string.h 语法/原型: int strcmp(const char* stri1,const char* str2); ...

  2. C语言 - strcmp和strncmp的编程实现及总结

    一.strcmp和strncmp的编程实现及总结 1.strcmp函数的实现 要求: 原型: int strcmp(char *dest,char * src,int n);        头文件:# ...

  3. day 14 C语言strcmp()函数:比较两个字符串

    (1).下列关于C语言文件的叙述中正确的是[C] (A).文件由一系列数据依次排列组成,只能构成二进制文件 (B).文件由结结构序列组成,可以构成二进制文件或文本文件 (C).文件由数据序列组成,可以 ...

  4. C语言strcmp()函数:比较字符串(区分大小写)

    头文件:#include <string.h> strcmp() 用来比较字符串(区分大小写),其原型为: int strcmp(const char *s1, const char *s ...

  5. RPM包的版本号比较

    版本号表示格式为 epoch:version-release,例如 1:2-3 第一条原则是 rpm 属性优先级 epoch > version > release        两个 r ...

  6. Redis核心原理与实践--字符串实现原理

    Redis是一个键值对数据库(key-value DB),下面是一个简单的Redis的命令: > SET msg "hello wolrd" 该命令将键"msg&q ...

  7. 转:C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文

    转自:C语言字符串操作函数 - strcpy.strcmp.strcat.反转.回文 C++常用库函数atoi,itoa,strcpy,strcmp的实现 作者:jcsu C语言字符串操作函数 1. ...

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

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

  9. C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文

    原文:http://www.cnblogs.com/JCSU/articles/1305401.html C语言字符串操作函数 1. 字符串反转 - strRev2. 字符串复制 - strcpy3. ...

随机推荐

  1. html css js 细节

    细节1 1.Chrome中文界面下会将小于12px的字体默认显示为12px,解决方法:在CSS中加入-webkit-text-size-adjust:none; 2.link可以加载除CSS以外的其他 ...

  2. 在Altium Designer 10中实现元器件旋转45°角放置

    Tool--->Preferences >> PCB Editor >> General 将Rotation Step(旋转的步进值)由90改为45,这样以后每次按空格键 ...

  3. javascript五种基本类型

    typeof 功能:检测变量的类型 语法:console.log(typeof  变量) 或  console.log(typeof (变量)): 五大基本类型 1.underfined 声明变量但是 ...

  4. 3、VNC

    VNC(Virtual Network Computing,虚拟网络计算机) VNC分为两部分组成:VNC server 和 VNC viewer VNC安装 1.yum install tigerv ...

  5. spring cloud 下载依赖慢解决方案

    可以在修改pom文件添加如下代码: <repositories> <repository> <id>spring-snapshots</id> < ...

  6. CentOS 7上安装Pure-FTPd

    # 安装 yum install epel-release yum install pure-ftpd 位置文件位于/etc/pure-ftpd/pure-ftpd.conf # 修改配置文件 # 注 ...

  7. .net core部署到Ubuntu碰到的问题

    数据库连接的时候,会报错“MySql.Data.MySqlClient.MySqlException:“The host localhost does not support SSL connecti ...

  8. 错误:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hdjyproj.t_userinfo' do ...

  9. CentOS 使用yum命令安装出现错误提示”could not retrieve mirrorlist http://mirrorlist.centos.org

    CentOS 使用yum命令安装出现错误提示"could not retrieve mirrorlist http://mirrorlist.centos.org这个错误, 在网上找了好多, ...

  10. LoadLibrary和GetModuleHandle

    0x01  区别 LoadLibrary是把一个模块映射进调用进程的地址空间,需要时增加引用计数,每调用一次,引用计数增加一,需要通过相同步骤地调用FreeLibrary来减少引用次数,当为0时,系统 ...