浅学strcmp

strcmp 头文件<string.h> 

string1 与 string2 的关系

< 0

string1 小于 string2。

0

string1 等于 string2

> 0

string1 大于 string2

#include <iostream>
#include <cstring>
using namespace std;
char* Max(char *a,char *b)
{
    int result;
    char *temp = NULL; 
    result = strcmp(a,b);
    if(result > 0)
        temp = a;
        else if(result < 0)
            temp = b;
    return temp;
}
int main()
{
    char string1[] = "The quick brown dog jumps over the lazy fox";
    char string2[] = "The QUICK brown dog jumps over the lazy fox";
    cout << Max(string1,string2);
    return 0;
}

输出结果: 

The quick brown dog jumps over the lazy fox

猜你喜欢

转载自blog.csdn.net/qq_37592750/article/details/83046481