/* * Program to copy text from stdin to stdout (i.e., echo). * * writes prompt and count of chars to stderr not stdout so we can use this * as a file-copy program, using I/O redirection */ #include void echo(void); int main(void) { fprintf(stderr, "enter some text\n"); int inchar; int count = 0; while ((inchar = fgetc(stdin)) != EOF) { count += 1; fputc(inchar, stdout); } /* another way inchar = getchar(); while (inchar != EOF) { count += 1; putchar(inchar); inchar = getchar(); } */ fprintf(stderr, "%d chars echoed\n", count); return 0; }