您的位置:首页 > 其它

字符串比较

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: