我需要有关该脚本的帮助。
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/