字符串比较函数不区分大小写比如 “DMX” and “dmx”
/*
字符串比较函数可以用int strcmp(const char *s1,const char *s2);但是其原型比较的ascii码的值的大小,但是对于大小写是不能相比较的。所以就有下边的字符串函数的比较函数,不区分大小写。
extern int strcmp(const char *s1,const char *s2);
规则
当s1<s2时,返回为负数;
当s1=s2时,返回值= 0;
当s1>s2时,返回正数。
*/
/*
*其参数
*const char *str1[in] 输入字符指针,也可为数组名
*const char *str2[in] 相比较的字符指针,也可为数组名
*int count [in] 比较的长度
*返回值
* 0表示相等,-1表示不相等
* 其实就是用到了一个toupper这样的函数,要用此函数必须引用#include <ctype.h>这个库
*/
#include <ctype.h>
// 字符串比较, 不区分大小写, 例如: str == STR
int strncmp_ul(const char *str1, const char *str2, int count)
{
int i = 0;
//比较两个字符串的长度
if ((strlen(str1) < count) || (strlen(str2) < count))
{
return -1;
}
//遍历每一个字符串里的字符利用toupper这个函数比较大小
while (i < count)
{
if (toupper(*str1) != toupper(*str2))
return -1;
i++;
++str1;
++str2;
}
return 0;
}
/*一下代码是总结实用的小程序*/
//注意用一下函数必须要引用一下库函数
#include <ctype.h>
#include "..\\inc\\ctype_plus.h"
// 检查参数c是否为空格字符, 也就是判断是否为空格(' ')
//int isspace(int c)
//{
// if(c == ' ') return 1;
// else return 0;
//}
// isblank() 用来判断一个字符是否为TAB或者空格, 其原型为:
// int isblank(int c);
// 【参数】c 为需要检测的字符.
// 【返回值】若 c 为TAB或空格, 返回非 0 值, 否则返回 0.
// 说明&#