c - strcmp 没有正确比较字符串

标签 c

<分区>

所以我有这个(不是完整的代码)

字符列表[1000][10];

strcpy(列表[0],"ab");

printf("%d\n",strcmp(list[0],"ab"));

并且 strcmp 返回 0。有人可以解释为什么会这样吗?

提前致谢。

最佳答案

strcmp如果 list[0] 在这种情况下包含“ab”,方法将返回 0。

它返回:

Returns an integral value indicating the relationship between the strings:

A zero value indicates that both strings are equal.

A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; And a value less than zero indicates the opposite.

关于c - strcmp 没有正确比较字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18412345/

相关文章:

c - 如何以正确的方式转换 void** 指针?

c - WaitForSingleObject 和 WaitForMultipleObjects 等同于 Linux?

C:无限循环黎曼积分问题

c - Unsigned integer 和 unsigned char 保持相同的值但表现不同为什么?

c - 使用信号处理程序从函数返回

c - 这个C程序有什么问题? (全局变量)

c - 我有一个文件名 ABCD_81018293.txt。我尝试 sscanf 将 ABCD 获取为文本,将数字获取为 int

c++ - 打印值 0x89 (-119) 时出现奇怪的输出

c - 将 MinGW 程序与 MSVC 静态库链接时发出警告

C:更快地访问查找表?