C语言笔试题(6)——strcmp函数的实现
来源:互联网 发布:json嵌套解析 编辑:程序博客网 时间:2024/04/30 04:50
原型:extern int strcmp(const char *s1,const char * s2);
用法:#include <string.h>
功能:比较字符串s1和s2。
一般形式:strcmp(字符串1,字符串2)
说明: 当s1<s2时,返回值<0 当s1=s2时,返回值=0 当s1>s2时,返回值>0
即:两个字符串自左向右逐个字符相比(按ASCII值大小相比较),直到出现不同的字符或遇'\0'为止。
#include <stdio.h>#include <assert.h>int strcmp(const char *str1, const char *str2){ int ret = 0; assert(str1 != NULL && str2 != NULL); while(!(ret = *(unsigned char *)str1 - *(unsigned char *)str2) && *str1) str1++, str2++; if (ret > 0) return 1; else if (ret < 0) return -1; return 0;}int main(int argc, const char *argv[]){ char str1[] = "he"; char str2[] = "hef"; int i = 0; i = strcmp(str1, str2); printf("%d\n", i); return 0;}
- C语言笔试题(6)——strcmp函数的实现
- 【笔试题】C语言:模拟实现strcmp
- 【C语言】strcmp函数的实现
- 【C语言】【面试题】【笔试题】模拟实现数据库中strcmp函数
- C语言实现strcmp函数
- C/C++——strcmp函数实现
- C/C++——strcmp函数实现
- C语言strlen, strcpy, strcmp,strcat函数的实现
- strcpy/strncpy/strcat/strcmp/strlen函数的c语言实现
- C语言实现strcmp()和strcpy()函数
- 【C语言】模拟实现strcmp函数
- 【C语言】模拟实现strcmp()、strncmp()函数
- 【c语言】模拟实现strcmp函数
- C语言函数strcmp
- 【C语言】strcpy(),strcat(), strcmp()函数的实现
- c语言学习笔记(字符串函数strcmp,strcat,strcpy,strlen的简单实现)
- C语言中字符串相关函数的实现(strcat strlen strcmp strcpy memcpy)
- C语言字符串函数的模拟实现(strlen、strcpy、strcat、strstr 、strcmp)
- 微机原理与接口技术之“MOV指令”
- main输入参数的含义和介绍
- 4wpa_supplicant适配层 -- 详解
- VS在打开不同SDK时常会出现无法加载该项目的提示
- 一步步 学数据结构 之 二
- C语言笔试题(6)——strcmp函数的实现
- WinGW的安装和配置
- struts2知识
- [gpu pro3]efficient online visibility for shadow maps
- jackson dynamic filter
- java内存分配
- jsp与html交互
- 僵尸进程 wait() waitpid()
- 使用winhex处理autorun.inf病毒