错误:添加明显的括号,以避免其他晃来晃去。 C [英] Error: add explicit braces to avoid dangling else. C

查看:2130
本文介绍了错误:添加明显的括号,以避免其他晃来晃去。 C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的gedit和我的编者是铿锵。
我已经得到了几个这些错误最近和不知道如何解决(在标题错误,指的是else语句)。

I'm using gedit and my complier is clang. I've been getting a couple of these errors recently and not sure how to fix (error in title and referring to the else statement).

 if(isupper(ptext[i]))
            if ((((ptext[i]+k)%26)+52) < 65 || (((ptext[i]+k)%26)+52) > 90)
            {
                printf("%c", (((ptext[i]+k)%26)+78));
            }
            else
            {
                printf("%c", (((ptext[i]+k)%26)+52));
            }

我应该添加/删除/修复?
在此先感谢:)

What should I add/remove/fix? Thanks in advance :)

推荐答案

您外如果缺少括号:

if(isupper(ptext[i]))
{
        if ((((ptext[i]+k)%26)+52) < 65 || (((ptext[i]+k)%26)+52) > 90)
        {
            printf("%c", (((ptext[i]+k)%26)+78));
        }
        else
        {
            printf("%c", (((ptext[i]+k)%26)+52));
        }
}

就个人而言,我会提取一些共同的元素到变量:

Personally, I would extract some of the common elements into variables:

char something1 = ptext[i];
if(isupper(something1))
{
    char something2 = (something1+k)%26;
    if ((something2+52) < 65 || (something2+52) > 90)
    {
        printf("%c", (something2+78));
    }
    else
    {
        printf("%c", (something2+52));
    }
}

和甚至把字符something3 = something2 + 52; 在那里了。当然,具有更多有意义的变量名。

And maybe even put a char something3 = something2 + 52; in there too. Of course, with more meaningful variable names.

这篇关于错误:添加明显的括号,以避免其他晃来晃去。 C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆