淺學strcmp
阿新 • • 發佈:2018-11-11
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