linux系统库函数之strcmp、strncmp
来源:互联网 发布:ubuntu 16.04进入图形 编辑:程序博客网 时间:2024/06/05 20:28
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大小数据。
- linux系统库函数之strcmp、strncmp
- strcmp() , strncmp();
- strcmp,strncmp函数实现——string.h库函数
- strcmp/strncmp/stricmp(windows) strcasecmp/strncasecmp(linux)
- linux系统库函数之memcpy
- linux系统库函数之memmove
- linux系统库函数之memset
- linux系统库函数之strlen
- Linux系统库函数之strsep
- PHP字符串函数之 strcmp strncmp strcasecmp strncasecmp strnatcmp strnatcasecmp
- string库之模拟实现strcmp、strncmp和memcmp
- strcmp 与strncmp
- strcmp与strncmp区别
- strcmp/strncmp源码分析
- strcmp()和strncmp()
- strcmp和strncmp
- C strcmp 与 strncmp
- C strcmp 与 strncmp
- android animation的应用实例
- linux下trap命令和SIGHUP信号量详解
- x509数字证书
- 查询数据库、对象、磁盘等信息
- sqlserver2012分页offset
- linux系统库函数之strcmp、strncmp
- power designer
- 一个较快速的JSON库——Fastjson
- SAP Workflow Add Attachment to Workflow and Generic Object Services
- 可连接点对象及示例(二)
- BMP 格式解析
- android 解析xml的三种方式(DOM,SAX,PULL)之SAX(转载收藏)
- 第五周实验报告4
- 关于/etc/host?