dev c++, c programme, every character is displaced by a square

Viewed 47
#include<stdio.h>
int main()
{
    char c;
    while((c=getchar()!=EOF))
    {
        putchar(c);//
    }
}

Every character of the output is displaced by '' these sorts of things.

enter image description here

1 Answers

Your parentheses are wrong so c gets assigned the value of the condition, which is 0 or 1 (false or true).

What you have now is the same as c = (getchar() != EOF) because of operator precedence.

Also, use the correct type for c, which is int:

#include<stdio.h>
int main()
{
    int c;
    while( (c = getchar()) != EOF )
    {
        putchar(c);//
    }
}
Related