#include ttyin() { char buf[BUFSIZ]; FILE *tty; tty = fopen("/dev/tty", "r"); if (fgets(buf, sizeof buf, tty) == NULL || buf[0] == 'q') exit(0); else return buf[0]; } main() { int c; char ans; char buf[BUFSIZ]; fprintf(stderr, "%s", "swap nl with space (y/n)? "); ans = ttyin(); if (ans == 'y' || ans == 'Y') { while(fgets(buf, sizeof buf, stdin) != NULL) { buf[strlen(buf)-1] = ' '; fputs(buf, stdout); } printf("\n"); } else while((c = getchar()) != EOF) putchar(c); exit(0); }