c - C中的 "passing argument 2 of strcmp makes pointer from integer without a cast"错误是什么意思?

标签 c strcmp

我正在编译我的 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' 是一个整数 - 具体来说,它是整数 1strcmp 的第二个参数必须是字符串,而不是整数。

您似乎打算将 argv[2]aA 进行比较。为此,您需要两个不同的 strcmp 调用。此外,您需要使用双引号,而不是单引号。

关于c - C中的 "passing argument 2 of strcmp makes pointer from integer without a cast"错误是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8937379/

相关文章:

c - 为什么 sha1 会为相同的输入字符串返回不同的哈希值?

c - 从文本文件中读取单词(一行中的单个单词)

c++ - 如何以编程方式(在 C/C++ 中)模拟 DOS 中的击键?

c++ - 当我调用 strcmp 从 'int' 到 'const char*' 的无效转换时出错

c - 如何正确比较 C 中的字符串?

c - 如何在c中读取图像的像素?

c - strcmp 的段错误,但字符串使用 printf 打印

c - strcmp() 没有返回它应该返回的内容

c - 用户名和密码验证 Turbo C

c - Linux c fork - 进程不停止