You may want to use strcmp
:
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
int v;
const char *str1 = "hello";
const char *str2 = "world";
v = strcmp(str1, str2);
if (v < 0)
printf("'%s' is less than '%s'.
", str1, str2);
else if (v == 0)
printf("'%s' equals '%s'.
", str1, str2);
else if (v > 0)
printf("'%s' is greater than '%s'.
", str1, str2);
return 0;
}
Result:
'hello' is less than 'world'.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…