2 votes 2 votes #include<stdio.h> main(){ int c; while(c = getchar() != '\n') putchar(c); } why does this program shows wrong output for every input string.. plzz some one help Abhinandan Sharma asked Aug 11, 2016 Abhinandan Sharma 618 views answer comment Share Follow See all 3 Comments See all 3 3 Comments reply Prashant. commented Aug 11, 2016 reply Follow Share what u want to do by this. 0 votes 0 votes ManojK commented Aug 11, 2016 reply Follow Share Precedance of = is right to left.So your program evaluated as main(){ int c; while(c = (getchar() != '\n')) putchar(c); } So on some input it will give unexpected result. If you want the correct output make some changes main(){ int c; while((c = getchar()) != '\n') putchar(c); } Now everything works fine. 4 votes 4 votes Prashant. commented Aug 11, 2016 reply Follow Share it should be while((c = getchar()) != '\n'); 1 votes 1 votes Please log in or register to add a comment.