Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why this program never printing '0'?

0 votes
asked Jan 18, 2021 by Vibha Mhetre (120 points)
#include<stdio.h>

int main(int argc, char *argv[]) {
    int c;

    while ((c = getchar()) != EOF) {
        printf("%d ", c != EOF);
        putchar(c);
    }

    printf("\n%d\n", c != EOF);

}

1 Answer

0 votes
answered Jan 2, 2022 by xDELLx (10,500 points)
This will print 0 only if ,

If you are running on Windows , hit "Cntrl+Z"

If you are on Linux, hit "Cntrl+D"

You dont want the code to execute the while () loop.So you have enter the EOF character in input.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...