简体   繁体   English

C程序中奇怪的输出

[英]Strange output in C Program

So I am just starting to learn C, I am using gcc if that makes any difference, and for some reason this simple program is giving me weird output: 所以我才刚刚开始学习C,如果有什么不同,我就在使用gcc,由于某种原因,这个简单的程序给了我奇怪的输出:

    #include <stdio.h>

    main()
    {
        int c;

        while (c == getchar() != EOF)
        {   
            putchar(c);
        }   
     }

I save it and use :!gcc % then :!./a.out in vim, when I type in any letter then Enter, it just gives me "^^" as the output. 我保存并在vim中使用:!gcc%然后:: ../ a.out,当我输入任何字母然后输入Enter时,它只是给我“ ^^”作为输出。 I searched around and couldn't find anyone else with this problem, and it's copied straight out of K&R so I don't know what could be causing this error, does anyone know what's going on? 我四处搜寻,找不到其他人遇到此问题,并且直接从K&R中复制了该问题,所以我不知道是什么原因导致此错误,有人知道这是怎么回事吗?

Ned Stark's answer is right, I had 2 equals signs and that's what was causing the weird errors. 内德·史塔克(Ned Stark)的回答是正确的,我有2个等号,这就是造成奇怪错误的原因。 Thanks for all the help guys! 感谢所有的帮助! Ned, if you want to post an answer I'll mark yours as correct, otherwise I'll mark this as correct in two days. 奈德,如果您想发布答案,我会标记为正确答案,否则我会在两天内标记为正确答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM