c++ - 错误 C2664 : 'strcmp' : cannot convert parameter 2 from 'char' to 'const char *'

标签 c++ strcmp

我需要有关该脚本的帮助。

BOOL Checking(LPCSTR MacID) {
    char ClientMacs[18] = { "11:22:33:44:55:66",};

    for(int x=0; x < 10; x++) {
        if(!strcmp(MacID, ClientMacs[x])) {
            printf(MacID," Successed!");
            return true;
        }
    }

    return false;
}

我得到了

error C2664: 'strcmp' : cannot convert parameter 2 from 'char' to 'const char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

当我尝试编译它时。

最佳答案

不是

if(!strcmp(MacID, ClientMacs[x])) {    }

但是

if(!strcmp(MacID, &ClientMacs[x])) { ... }

Arg 2 必须是 char *,但您将其作为 char。如果你的 arg 2 是普通的

  ClientMacs  // compiler understands that this is shorthand for &ClientMacs[0]

这样就好了。但是当索引不为零时,您必须将与号放在一起。

-- 皮特

关于c++ - 错误 C2664 : 'strcmp' : cannot convert parameter 2 from 'char' to 'const char *' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5452045/

相关文章:

c++ - 选择以 libxml2 结尾的行

c++ - "Argument of Type Incompatible"来自继承类

C++:使用 Boost 序列化来写入/读取文件

c++ - 如何创建文件路径可以像磁盘一样访问的虚拟文件系统

c - 如何解决字符串比较错误中的常量指针

c - 使用结构体数组进行选择排序,使用 strcmp 进行排序

c++ - C++中具有友元函数的多态性

我可以得到一些关于我用 C 实现的 strcmp() 函数的反馈吗?

c - strcmp() 有一些问题 - 代码编译但似乎不起作用

C: 带有输入大小的 strcmp 和 stdin 参数