Jordan Baron
Jordan Baron

Reputation: 4180

putchar() not returning value?

I am using the book 'The C Programming Language' to learn C.

I copied code exactly but the putchar() won't return the value of what the user types in.

#include <stdio.h>

main()
{
    int c;

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

If I input this

c

I don't get any output

Upvotes: 0

Views: 802

Answers (1)

duncan
duncan

Reputation: 1161

Try this:

int main()
{
    int c;

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

Upvotes: 3

Related Questions