fscanf(stderr,"%d",&i); ?!?!?

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Fri Apr 26 14:35:11 AEST 1991


In article <1010 at dri500.dri.nl>, heinhuis at dri.nl (Gustaaf-Jan Heinhuis) writes:
> Ever tried to read from screen??????? 
> Since when is stderr linked to a keyboard?????!!!!!!!!

In UNIX, stderr is typically what you'd get from
	stderr = fdopen(2, "w");
It doesn't make sense to read from stderr, because it's set up as an
output file.  But the standard error descriptor, if it is connected to
a terminal (which it need not be) is bidirectional, and it does make
sense to read from it.  So
	FILE *ttyin = fdopen(2, "r");
might well work.

> >and also, could you show me a way to
> >write a program that takes input from both redirected stdin
> >and keyboard?  Many thanks in advance.

The best answer that I know of is to open a new stream to the terminal.
Leave stdin connected to whatever it is connected to by the caller, then
in UNIX, just do
	FILE *ttyin = fopen("/dev/tty", "r");
In MS-DOS, I guess
	FILE *ttyin = fopen("con", "r");
might work.

<-- 
Bad things happen periodically, and they're going to happen to somebody.
Why not you?					-- John Allen Paulos.



More information about the Comp.lang.c mailing list