strcmp(s1,s2)
  说明:
  当s1<s2时,返回值<0
  当s1=s2时,返回值=0
  当s1>s2时,返回值>0
两个字符串自左向右逐个字符相比(按ASCII值大小相比较),直到出现不同的字符或遇'\0'为止。

char *str="aaaa",*ch="bbbbb";
if(strcmp(str,ch)>0) //成立就是字符串str在字符串ch后面
if(strcmp(str,ch)==0) //成立就是字符串内容一致
if(strcmp(str,ch)<0) //成立就是字符串str在字符串ch前面

int strcompare(char *s1,char *s2)
{
while(*s1==*s2&&*s1)
{
s1++;
s2++;
}
return (*s1-*s2);
}
即把两个字符串相对应的字符拿出来进行比较,返回第一个不等的字符比较的大小即可。C语言系统为用户提供了库函数strcmp可以实现以上函数功能。调用格式为:strcmp(s1,s2);
teacher 和teaching,第一个不等的字符是teacher的e和teaching的i,所以teaching大

c语言字符串比较函数strcmp的更多相关文章

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

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

  2. 【C】——C语言字符串比较函数

    c语言字符串函数详解 void *memset(void *dest, int c, size_t count); 将dest前面count个字符置为字符c. 返回dest的值. void *memm ...

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

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

  4. C语言字符串比较(转)

    #include <string.h>char s1[10],s2[10]; ... if(strcmp(s1,s2)==0) printf("两字符串相等\n"); ...

  5. 13-C语言字符串函数库

    目录: 一.C语言字符串函数库 二.用命令行输入参数 回到顶部 一.C语言字符串函数库 1 #include <string.h> 2 字符串复制 strcpy(参数1,参数2); 参数1 ...

  6. C语言 字符串操作 笔记

    /* C语言字符串的操作笔记 使用代码和注释结合方式记录 */ # include <stdio.h> # include <string.h> int main(void) ...

  7. C++语言字符串处理函数

    C++语言提供了比C语言更丰富的字符串处理功能.它可以在字符串上经行输入,输出,合并,修改,比较,转换,复制,搜索等操作.使用这些现成的功能可以大大减少我们的编程的负担. 输入和输出的字符串函数,如p ...

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

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

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

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

随机推荐

  1. 使用repo的本地开发流程

    repo下的本地开发流程 单分支开发:    1 本地新建工作目录并初始化repo库: repo init;    2 下载代码(只取服务器当前分支): repo sync -c;    3 创建本地 ...

  2. C# using垃圾回收详解

    简介 定义一个范围,将在此范围之外释放一个或多个对象. 语法 using (Font font1 = new Font("Arial", 10.0f)) { } C# 语言参考 主 ...

  3. C#控制条码打印机 纸张大小,间距,绘制内容(所有条码打印机通用)

    其他条码知识 请访问:http://www.ybtiaoma.com ,本文仅供参考,请勿转载,谢谢 using System; using System.Drawing; using System. ...

  4. right way check file open and end

    check if a state is ok while(cin >> word) // ok: read successful condition states are constant ...

  5. [转]Python存取XML方法简介

    转自:http://www.cnblogs.com/salomon/archive/2012/05/28/2518648.html 目前而言,Python 3.2存取XML有以下四种方法: 1.Exp ...

  6. (原)ippicvmt.lib(ippinit.obj) : error LNK2005: _ippSetCpuFeatures@8 已经在 ippcoremt.lib(ippinit.obj) 中定义

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5497234.html 参考网址: http://answers.opencv.org/question ...

  7. shell中的环境变量

    局部(local)环境变量 定义局部环境变量的方式如下: variableName=value 需要注意的是variableName前面没有$符号,并且=两边没有空格. 局部环境变量只能在当前shel ...

  8. ajax + php + Controller 控制所有后台函数调用

    转载请注明出处:http://www.cnblogs.com/ghypnus/p/4645873.html 好久没有来这边发布代码了 总共分成3大部分来完成php的ajax调用逻辑,以下是大致的结构 ...

  9. php过滤iphone的emoji表情

    public static function removeEmoji($text) { $clean_text = ""; // Match Emoticons $regexEmo ...

  10. 在服务器上php执行某些远程函数出错

    Warning: imagecreatefromjpeg(): php_network_getaddresses: getaddrinfo failed: Name or service not kn ...