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

本文介绍了C语言中用于比较两个字符串的strcmp函数及其不区分大小写的版本strcmpi函数。通过实例展示了如何使用这两个函数来比较字符串,并解释了它们返回值的意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

欢迎访问我的新博客: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/archive/2013/05/19/3808893.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值