我正在编译我的 C 代码并遇到两个错误:
warning:passing argument 2 of strcmp makes pointer from integer without a cast
和
warning: note: expected const char * but argument is of type int
这是我的主要内容:
int main(int argc, char *argv[])
{
//check to make sure that the command line arguments are valid
if(argc!=3)
{
printf("invalid function call try again\n");
}
//else to choose the proper command
else
{
//reverse routine A
if(strcmp(argv[2],'a'||'A')==0) //line 138
{
reva(argv[1]);
}
//reverse routine B
else if(strcmp(argv[2],'b'||'B')==0) //line 143
{
revb(argv[1]);
}
//reverse routine C
else if(strcmp(argv[2],'c'||'C')==0) //line 148
{
revc(argv[1]);
}
//unacceptable command line argumant
else
{
printf("unacceptable command line argument for reverse routine try again:\n");
}
}
}
最佳答案
意思就是它所说的。 'a'||'A'
是一个整数 - 具体来说,它是整数 1
。 strcmp
的第二个参数必须是字符串,而不是整数。
您似乎打算将 argv[2]
与 a
和 A
进行比较。为此,您需要两个不同的 strcmp
调用。此外,您需要使用双引号,而不是单引号。
关于c - C中的 "passing argument 2 of strcmp makes pointer from integer without a cast"错误是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8937379/