code未达到使用与fgets语句? [英] Code not reaching statements using fgets?

查看:120
本文介绍了code未达到使用与fgets语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了使用与fgets函数与调用code,即和amethod方法中bMethod等功能多个条件code。

I have written code that uses the fgets function with multiple conditions that call other functions within the code, namely aMethod and bMethod.

int main(void) {
char buffer[1024];
while (fgets(buffer, 1024, stdin)) {
    if ((strcasecmp(buffer,"a")) == 0) {
        aMethod();
        }
    if ((strcasecmp(buffer, "b")) == 0) {
        bMethod();
        }
    }
}

我不知道它为什么不if语句到达。
任何帮助将是巨大的,三江源。

I'm not sure why it doesn't reach the if statements. Any help would be great, thankyou.

推荐答案

如果有疑问,打印出来:

If in doubt, print it out:

int main(void) {
char buffer[1024];
while (fgets(buffer, 1024, stdin)) {
    fprintf(stderr, "BUFFER is [%s]\n", buffer);   /* <==== */
    if ((strcasecmp(buffer,"a")) == 0) {
        aMethod();
        }
    if ((strcasecmp(buffer, "b")) == 0) {
        bMethod();
        }
    }
}

您会发现很多错误的这种方式。

you will find a lot of errors this way.

这篇关于code未达到使用与fgets语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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