strcmp字符串比较函数

摘自linux内核4.11.1源码string.c
linux/lib/string.c
Copyright (C) 1991, 1992  Linus Torvalds

头文件:#include
作用: 比较两个字符串cs和ct
参数:
cs:字符串一
ct:字符串二
返回值:
1、若cs和ct相等,返回0
2、若cs大于ct,返回正值
3、若cs小于ct,返回负值
/**
 * strcmp - Compare two strings
 * @cs: One string
 * @ct: Another string
 */
int strcmp(const char *cs, const char *ct)
{
	unsigned char c1, c2;


	while (1) {
		c1 = *cs++;
		c2 = *ct++;
		if (c1 != c2)
			return c1 < c2 ? -1 : 1;
		if (!c1)
			break;
	}
	return 0;
}


你可能感兴趣的:(string)