字符串比较
2016-02-23 10:26
148 查看
1 #include "stdafx.h" 2 #include "iostream" 3 #include "assert.h" 4 5 using namespace std; 6 7 int mystrcmp(const char* dest, const char* src) 8 { 9 assert (dest!=NULL && src!=NULL); 10 while (*dest++ == *src++) 11 { 12 if (*dest=='\0' || *src=='\0') 13 break; 14 } 15 return *dest > *src ? 1 : (*dest==*src ? 0 : -1); 16 } 17 18 int main(int argc, char* argv[]) 19 { 20 printf("Hello World!\n"); 21 cout << mystrcmp("abc", "abcd"); 22 cout << endl; 23 return 0; 24 }
输出:
Hello World!
-1
Press any key to continue
相关文章推荐
- 字符串链接strcat
- ZK 最少限度加载页面js文件
- dcpromo(server2012不支持)
- javaScript里的二维数组转换为json格式的字符串
- Android&java的成长之路之六(2048小游戏②)
- MapReduce工作原理图文详解
- SQLAlchemy 笔记 ORM方式访问数据库
- Redis学习到实战(一)基础与入门
- 修改oracle用户密码永不过期
- 全球域名商解析新增保有量21强:易名夺冠 西数榜尾
- js加减乘除运算重写
- 常见SSL错误和解决办法
- Java系统调优:内存管理与垃圾回收
- UNDO 表空间使用率100%
- WindowsAPI - Net - WSAStartup - Baidu.com
- solr入门
- 判断回文字符串
- 字符串复制strncpy
- iOS开发-CocoaPods使用详细说明
- Qt之QTableView添加复选框(QAbstractItemDelegate)