discarding stdin

I have one more problem with my rot5/rot13 program.
If the user types
 
echo test12345 | rot --help

it is wrong but a user can try anyway. I see tools like grep have no OS error (broken pipe) like mine does. How do I get rid of all stdin data (when there is some stdin data) when I don't want to use it?
That's because "Programs with a well-written command line interface discriminate among their audience." [1]

There is a little function (usually in <unistd.h> or <io.h>, but more likely in random places on Windows) called
int isatty( int fd );

For convenience (especially on non-POSIX systems), you can use the macros
1
2
3
STDIN_FILENO
STDOUT_FILENO
STDERR_FILENO

for the appropriate file descriptor.

[1] http://www.ginac.de/~kreckel/fileno/
A good reference which provides code to get a file descriptor given a C++ stream.

Hope this helps.
Topic archived. No new replies allowed.