strcmp()与strcmpi()函数 C语言

欢迎访问我的新博客:http://www.milkcu.com/blog/

原文地址:http://www.milkcu.com/blog/archives/1368947100.html

strcmp()函数

函数名: strcmp
功能: 串比较
用法: int strcmp(char *str1, char *str2);

less than 0 - str1 is less than str2
equal to 0 - str1 is equal to str2
greater than 0 - str1 is greater than str2

测试函数:

# include <stdio.h>
# include <string.h>
int main(void)
{
	const char * a;
	const char * b;
	a = "Hello";
	b = "world";
	printf("%d\n", strcmpi(a, b));
}

应用举例:

注意:

  • &name为指向指针的指针;
  • (char *)确保编译器不报错。

# include <stdio.h>
# include <string.h>
int main(void)
{
	char * name;
	printf("Enter your name: ");
	scanf("%s", & name);    //指向指针的指针 
	if(strcmp((char *)& name, "MilkCu") == 0) {    //(char *)确保编译器不报错
	printf("Hello, MilkCu.\n");
	}
}

strcmpi()函数

strcmpi()与strcmp()相比,只是不区分大小写。

(全文完)

原文地址:https://www.cnblogs.com/milkcu/p/3808893.html