函数 strncmp

来源:互联网 发布:刚转行做程序员后悔了 编辑:程序博客网 时间:2024/05/02 05:01
strncmp(const char * a1,const char *a2,int maxlen)
与上面的函数类似),用来比较a1和a2两个字符串的,但是之比较两个字符串的钱maxlen长度的字符串
当a1<a2时候,返回的值<0
当a1>a2时候,返回的值>0
当a1=a2时候,返回的值=0

函数实现代码:
/*** strncmp - Compare two length-limited strings* @cs: One string* @ct: Another string* @count: The maximum number of bytes to compare*/int strncmp(const char *cs, const char *ct, size_t count){        signed char __res = 0;        while (count) {                if ((__res = *cs - *ct++) != 0 || !*cs++)                        break;                count--;        }        return __res;}
0 0
原创粉丝点击