#include <string.h>
声明:
int strcmp(const char *str1, const char *str2)
参数:
str1 – 要进行比较的第一个字符串。
str2 – 要进行比较的第二个字符串。
返回值:(比较指定的ASCII值)
如果 str1 < str2。返回值< 0,
如果 str2 > str1。返回值> 0
如果 str1 = str2,返回值 = 0
如
if (strcmp(c,d)==0)
cd如果相当
两个字符串自左向右逐个字符相比(按ASCII值大小相比较),直到出现不同的字符或遇'\0'为止。如:
1."A"<"B" 2."A"<"AB" 3."Apple"<"Banana" 4."A"<"a" 5."compare"<"computer"
比如判断输入的双十一:11 11
#include<stdio.h>
#include<string.h>
int main()
{
int yon;
char c[5] = "11 11",d[5];
float tip,jh11,jh12;
scanf("%f %5c %d",&tip,&d,&yon);
jh11=((0.7*tip-50)>0)?(0.7*tip-50):0;
jh12=((0.8*tip-50)>0)?(0.8*tip-50):0;
if (strcmp(c,d)==0)//1111
{
if(yon==1)
printf("%.2f",jh11);
else
printf("%.2f",0.7*tip);
}
else
{
if(yon==1)
printf("%.2f",jh12);
else
printf("%.2f",0.8*tip);
}
return 0;
}
输入11 11不通过
但当
char c[6] = "11 11",d[6];
通过✌
特别注意:strcmp(const char *s1,const char * s2)这里面只能比较字符串,即可用于比较两个字符串常量,或比较数组和字符串常量,不能比较数字等其他形式的参数。