在 C 中使用以下程序,字符串比较不起作用:
#include<stdio.h>
#include<string.h>
int main(){
char ch[]="ABC";
printf("%d \n", strlen(ch)); // output 3
printf("%d \n", strlen("ABC")); // output 3
if(strcmp("ABC",ch)){
printf("\n Matched");
}else{
printf("\n Not matched"); // this will be output
}
if("ABC" == ch){
printf("\n Matched");
}else{
printf("\n Not matched"); // this will be output
}
}//ends main
Run Code Online (Sandbox Code Playgroud)
输出是:
3
3
Not matched
Not matched
Run Code Online (Sandbox Code Playgroud)
为什么字符串不匹配?