Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!munnari.oz.au!bruce!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: fscanf(stderr,"%d",&i); ?!?!? Message-ID: <5404@goanna.cs.rmit.oz.au> Date: 26 Apr 91 04:35:11 GMT Article-I.D.: goanna.5404 References: <1991Apr2.083400.5511@athena.mit.edu> <1010@dri500.dri.nl> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 28 In article <1010@dri500.dri.nl>, heinhuis@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.