Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!uunet!mcsun!hp4nl!dri500!heinhuis From: heinhuis@dri.nl (Gustaaf-Jan Heinhuis) Newsgroups: comp.lang.c Subject: Re: fscanf(stderr,"%d",&i); ?!?!? Message-ID: <1010@dri500.dri.nl> Date: 23 Apr 91 13:57:06 GMT References: <1991Apr2.083400.5511@athena.mit.edu> <1991Apr23.075320.9473@en.ecn.purdue.edu> Organization: DataCount Register Informatici, Wierden, The Netherlands Lines: 45 In article <1991Apr23.075320.9473@en.ecn.purdue.edu> tenka@en.ecn.purdue.edu (Andy Tenka) writes: >In desperation to get the input from keyboard, I used: > > fscanf(stderr,"%d",&i); > >However, the fscanf does not wait for input from keyboard. >It just reads 0 from stderr before I even type anything. >I know I did something wrong here. Could any of you gurus >point out my mistakes Ever tried to read from screen??????? Since when is stderr linked to a keyboard?????!!!!!!!! The kernel links stdin to the keyboard (_iob[0]), stdout an stderr to the screen (_iob[1] and _iob[2] resp.) *****before***** the program starts. Redirecting results in the kernel linking stdin to the file instead of to the keyboard. >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. This is elementary (do hope I will not regret this remark, no flames) You simply open a file for reading ( fopen(filename, "w") ). You have three options: 1): supply filename as an argument to your program. 2): let the user supply the filename ( scanf("%s", &name) ) 3): you always read from the same file, i.e. filename is a string constant. Hope this helps, Gustaaf-Jan. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++---===To all virgins, thanks for nothing.===---++++++++++++++ ___ GJ Heinhuis student comp. sc. HIO Enschede (Holland) / _) Final Project at: DataCount, Wierden, Holland | ____ ___ Mail: heinhuis@dri.nl \__/| | |___| Everybody is entitled to his own | | | opinion, as long as it's mine! \_/ | Not necessarely DataCount's opinion!!