/* * Program to echo text from stdin to stdout and print number of characters * copied. * * Prompt and number of characters go to stderr rather than stdout so we * could use this as a file-copy utility. */ #include int main(void) { fprintf(stderr, "enter text, control-D to end\n"); int ch; int count = 0; while ((ch = getchar()) != EOF) { putchar(ch); count += 1; } fprintf(stderr, "%d characters echoed\n", count); return 0; }