linux系统库函数之strcmp、strncmp

240 #ifndef __HAVE_ARCH_STRCMP
241 /**
242  * strcmp - Compare two strings
243  * @cs: One string
244  * @ct: Another string
245  */
246 #undef strcmp
247 int strcmp(const char *cs, const char *ct)
248 {
249         unsigned char c1, c2;
250 
251         while (1) {
252                 c1 = *cs++;
253                 c2 = *ct++;
254                 if (c1 != c2)
255                         return c1 < c2 ? -1 : 1;
256                 if (!c1)
257                         break;
258         }
259         return 0;
260 }
261 EXPORT_SYMBOL(strcmp);

262 #endif

字符串比较函数,如果两个字符串相等,则返回0,否则返回非零值。

264 #ifndef __HAVE_ARCH_STRNCMP
265 /**
266  * strncmp - Compare two length-limited strings
267  * @cs: One string
268  * @ct: Another string
269  * @count: The maximum number of bytes to compare
270  */
271 int strncmp(const char *cs, const char *ct, size_t count)
272 {
273         unsigned char c1, c2;
274 
275         while (count) {
276                 c1 = *cs++;
277                 c2 = *ct++;
278                 if (c1 != c2)
279                         return c1 < c2 ? -1 : 1;
280                 if (!c1)
281                         break;
282                 count--;
283         }
284         return 0;
285 }
286 EXPORT_SYMBOL(strncmp);
287 #endif

同样的是,如果没有遇到字符串结束符,只比较cuont大小数据。

转载于:https://www.cnblogs.com/phonegap/archive/2012/03/20/2536109.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值