people in the way 2021-07-06 15:41 采纳率: 28.6%
浏览 48
已采纳

c语言弱鸡求解goto用法

求解大神么输出结果为什么是
q
STEP3
step1
step2
STEP3
而不是
q
STEP3
step1
step2

int main(void)
{
    char ch;
    while((ch=getchar())!='#')
    {
        laststep:printf("STEP3\n");
        if(ch=='\n')
            continue;
        printf("step1\n");
        if(ch=='c')
            continue;
        else if(ch=='b')
            break;
        else if(ch=='g')
            goto laststep;
        printf("step2\n");
    }
    
    printf("DONE\n");
    getchar();
    getchar();
    return 0;
}


  • 写回答

3条回答 默认 最新

  • peng450 2021-07-06 15:53
    关注

    在这里你不只是输入了q, 而是 q\n 这两个字符。输入q时准确按照你的思路,只不过还有一个循环读取\n.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?