strcmp函数
strcmp函数用于c语言中两个字符串比较(只可以比较字符串,不可以比较数字)
规则
当s1>s2时,返回为正数;
当s1=s2时,返回值为0;
当s1<s2时,返回为负数;
两个字符串自左向右相比,比较ASCLL值大小,到'/0'停止。
例如:‘a’<'b' 'A'<'B' "computer">"compare"
实例
#include<stdio.h>
#include<string.h> //头文件
main()
{
char s1[20],s2[20];
int i;
gets(s1);
gets(s2);
i=strcmp(s1,s2); //strcmp比较结果赋值给i
if(i>0)
printf("%s",s1);
else if(i==0)
printf("s1=s2");
else
printf("%s",s2);
}
输入:
abcd efg;
输出结果:
efg;
strcmp函数的更多相关文章
- 转:strcmp函数实现及分析
转自:strcmp函数实现及详解 strcmp函数是C/C++中基本的函数,它对两个字符串进行比较,然后返回比较结果,函数形式如下:int strcmp(constchar*str1,constcha ...
- strstr函数与strcmp函数
1.strstr函数主要完成在一个字串中寻找另外一个字串 函数实现工程如下:摘自http://baike.baidu.com/link?url=RwrzOxs0w68j02J2uQs5u1A56bEN ...
- strcmp函数实现及分析
最近看C,看到strcmp函数,对它的实现原型不很清楚,于是到网上搜.网上算法一大堆,看了很多代码后自己做了一下总结 strcmp函数是C/C++中基本的函数,它对两个字符串进行比较,然后返回比较结果 ...
- strcmp函数和strcpy函数
(一)strcmp函数 strcmp函数是比較两个字符串的大小,返回比較的结果.一般形式是: i=strcmp(字符串,字符串); 当中,字符串1.字符串2均可为字符串常量或变量:i 是用于存放比 ...
- 自己写一个strcmp函数(C++)
题目说明: 写一个函数,实现两个字符串的比较.即自己写一个strcmp函数,函数原型为int strcmp( char * p1, char * p2); 设p1指向字符串s1,p2指向字符串s2.要 ...
- 算法提高 11-1实现strcmp函数
问题描述 自己实现一个比较字符串大小的函数,也即实现strcmp函数.函数:int myStrcmp(char *s1,char *s2) 按照ASCII顺序比较字符串s1与s2.若s1与s2相等返回 ...
- strlen函数,strcat函数,strcpy函数,strncpy函数,strcmp函数
strcpy函数: char *strcpy(char *Dest , const char *Src) { assert((Dest != NULL) && (Src != NULL ...
- 转自:strcmp函数实现及详解
strcmp函数是C/C++中基本的函数,它对两个字符串进行比较,然后返回比较结果,函数形式如下:int strcmp(constchar*str1,constchar*str2);其中str1和st ...
- php strcmp()函数
<? $str = "LAMP"; $str1 = "LAMPBrother"; $strc = strcmp($str,$str1); switch ( ...
随机推荐
- ADO.NET生成的数据库连接字符串解析
1.概述 当我们使用ADO.NET数据实体模型生成的时候,在项目目下生成一个.edmx文件的同时,还会在app.config里面出现如下一个代码串: <?xml version="1. ...
- Bluetooth A2DP --Audio payload type
数据结构: 字段解释: payload type: 0x60(96), dynamic type type 定义: https://www.iana.org/assignments/rtp-param ...
- Leetcode题解(十六)
44 ----------------------------------------------------------------分割线------------------------------ ...
- replace to
要注意的是:插入数据的表必须有主键或者是唯一索引!否则的话,replace into 会直接插入数据,这将导致表中出现重复的数据. MySQL replace into 有三种形式: 1. repla ...
- 使用PostgreSQL进行全文检索
* { color: #3e3e3e } body { font-family: "Helvetica Neue", Helvetica, "Hiragino Sans ...
- SQL Server远程连接(2)
- html的块级元素和内联元素
常用的块级元素: address , center , div , dl ,, form , h1 , h2 , h3 , h4 , h5 , h6 , menu , ol , p , table , ...
- javascript中new操作符
当代码var p= new Person("tom")执行时,其实内部做了如下几件事情: 1.创建一个空白对象(new Object()). 2.拷贝Person.prototyp ...
- Deploy .Net project automatically with MsBuild and MsDeploy (1)
Q: How to change parameter values in configuration files dynamically In the first section http://www ...
- NFS服务
第1章 NFS介绍 1.1 NFS的概念 NFS是Network File System的缩写,即网络文件系统,它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录.NFS客户 ...