#include <string.h>
int strcmp( const char *str1, const char *str2 );
比较字符串str1 和 str2, 返回值如下:
小于0:str1 小于 str2
等于0:str1 等于 str2
大于0:str1 大于 str2
#include <string.h>
#include <stdio.h>
int main(void)
{
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
int ptr;
ptr = strcmp(buf2, buf1);
if (ptr > 0)
{
printf("buffer2 > buffer1\n");
}
else
{
printf("buffer2 < buffer1\n");
}
ptr = strcmp(buf2, buf3);
if (ptr > 0)
{
printf("buffer2 > buffer3\n");
}
else
{
printf("buffer2 < buffer3\n");
}
return 0;
}输出结果:
buffer2 > buffer1 buffer2 < buffer3