Tag: strcmp

左值作为赋值的左操作数

我为什么要来 lvalue required as left operand of assignment 用单个字符串比较? 我怎样才能在C解决这个问题? if (strcmp(“hello”, “hello”) = 0) 谢谢!

如何正确比较命令行参数?

我正在尝试编写一个在main中接受参数的C代码; 因此,当我在cmd中编写一些字符串时,程序会在其中执行某些操作。 但我做错了什么,我找不到它。 这是代码: #include #include int main(int argc, char * argv[]){ //File name is main.c if(argc != 3) printf(“Wrong!!!!!!!!!”); else if (argv[1] == “-s”) girls(); //Prints “Girls” else if(argv[1] == “-k”) boys(); //Prints “Boys” else printf(“OMG!!”); } 在cmd; gcc -o gender main.c gender -s pilkington 我输入那些命令。 总是输出 “我的天啊!!” 哪部分错了?

strcmp()在C中完全返回什么?

我在C中写了这段代码: #include #include #include #include int main() { char string1[20]; char string2[20]; strcpy(string1, “Heloooo”); strcpy(string2, “Helloo”); printf(“%d”, strcmp(string1, string2)); return(0); } 控制台打印值是1还是o值和\0字符的ASCII值之间的差值,即111? 在这个网站上写道,这应该给出111,但当我在我的笔记本电脑上运行时,它显示1.为什么?

strcmp()返回C中的值

我正在学习C中的strcmp() 。我知道当两个字符串相等时, strcmp返回0。 但是,当手册页指出strcmp在第一个字符串小于第二个字符串时返回小于0时,它是指长度,ASCII值还是其他什么?