函数关键字: strcmp
使用格式:类型strcmp (参数1、参数2 ) )。
功能:在比较参数1和参数(1、参数1参数2时,返回正数; 2、参数1参数2时,返回负数; 3、参数1=参数2时,返回0; )
例:
#include string.h
#include stdio.h
入主(void ) )。
{
char *buf1='aaa '、*buf2='bbb '、*buf3='ccc ';
int ptr;
ptr=strcmp(buf2,buf1);
是if(ptr0 )
{ printf (buf2isgreaterthanbuf1(n );
}
else
{
打印(buf2islessthanbuf1(n ) );
}
ptr=strcmp(buf2,buf3);
是if(ptr0 )
{ printf (buff2isgreaterthanbuf3(n ); }
else
{
printf(buf2islessthanbuf3(n );
}
返回0;
}