比较两个字符串
来源:互联网 发布:2016年养殖业数据 编辑:程序博客网 时间:2024/06/05 21:56
用数组名作形参
#include <iostream>#include <string.h>using namespace std;int astrcmp(const char str1[], const char str2[]);int main(){ char s1[50]="Hello world. "; char s2[50]="Good morning! "; switch (astrcmp(s1,s2)) { case 0: cout<<"s1与s2相等"; break; case 1: cout<<"s1大于s2"; break; case 3: cout<<"s1小于s2"; break; } return 0;}int astrcmp(const char str1[], const char str2[]){ int i=0,n; while(1) { if(str1[i]!='\0'&&str2[i]!='\0') { if(str1[i]==str2[i]) { n=0; i++; } else { if(str1[i]>str2[i]) { n=1; } else { n=2; } break; } } else { if(str1=='\0') { n=2; } else { n=1; } break; } } return n;}
用指针作形参
#include <iostream>#include <string.h>using namespace std;int astrcmp(const char *, const char *);int main(){ char s1[50]="Hello world. "; char s2[50]="Good morning! "; switch (astrcmp(s1,s2)) { case 0: cout<<"s1与s2相等"; break; case 1: cout<<"s1大于s2"; break; case 3: cout<<"s1小于s2"; break; } return 0;}int astrcmp(const char *str1, const char *str2){ int i=0,n; while(1) { if(*(str1+i)!='\0'&&*(str2+i)!='\0') { if(*(str1+i)==*(str2+i)) { n=0; i++; } else { if(*(str1+i)>*(str2+i)) { n=1; } else { n=2; } break; } } else { if(*(str1+i)=='\0') { n=2; } else { n=1; } break; } } return n;}
0 0
- javascript 比较两个字符串
- 比较两个字符串。
- 比较两个字符串
- 比较两个字符串大小
- 17.2比较两个字符串
- 比较两个字符串
- 比较两个字符串2
- 汇编比较两个字符串
- 两个字符串的比较
- 两个字符串比较差异
- JSTL比较两个字符串
- 比较两个字符串是否相等?
- 两个字符串分段后比较
- JavaScript正则比较两个字符串
- 两个字符串比较是否相同
- sql比较两个字符串.txt
- 17_2_2比较两个字符串
- 比较两个字符串的大小
- c#设计模式- Abstract Factory模式(抽象工厂)
- 17周 项目2.3 求字符串的长度并返回
- AlertDialog dismiss 和 cancel方法的区别
- 内联汇编
- Ubuntu下samba的安装设置
- 比较两个字符串
- Android音频系统之音频框架
- LSAT的逻辑组题 6
- C++ 二维数组动态创建和内存释放
- c语言中的可变参数传值
- 蓝洁瑛白发苍老 自曝曾遭两影坛大哥强奸
- 并行查询的执行计划解读
- request.getRealPath("/")
- 在eclipse LDT(Koneki)中搭建quick-cocos2d-x的lua开发环境