为什么strcmp()中的'OR运算符'不起作用?

问题描述 投票:-1回答:1
    char text[10];
    fgets(cmd, 10, stdin);

    if (strncmp(cmd, "some text one",13 || "some text two",8) == 0)
    {
        puts("some text");
    }

    if (strncmp(cmd, "some text three",13 || "some text four",13) == 0)
    {
        puts("some text again");
    }

我想在这里使用OR运算符,但是当我运行它并输入“ some text one”-输出是这样的:

some text
some text again

为什么?

c if-statement operators strcmp
1个回答
0
投票

您不能将OR运算符放在strncmp()调用的中间。您必须为每个比较分别调用它。

© www.soinside.com 2019 - 2024. All rights reserved.