Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!bcm!shell!shell!rjohnson From: rjohnson@shell.com (Roy Johnson) Newsgroups: comp.lang.c Subject: Re: fscanf(stderr,"%d",&i); ?!?!? Message-ID: Date: 24 Apr 91 16:54:23 GMT References: <1991Apr2.083400.5511@athena.mit.edu> <1991Apr23.075320.9473@en.ecn.purdue.edu> <1010@dri500.dri.nl> Sender: usenet@shell.shell.com (USENET News System) Organization: Shell Development Company, Bellaire Research Center, Houston, TX Lines: 29 In-Reply-To: heinhuis@dri.nl's message of 23 Apr 1991 13:57:06 GMT In article <1010@dri500.dri.nl> heinhuis@dri.nl (Gustaaf-Jan Heinhuis) writes: >In article <1991Apr23.075320.9473@en.ecn.purdue.edu> >tenka@en.ecn.purdue.edu (Andy Tenka) writes: >>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. Fine, unless you want to use it as a pipe and still get input from the user. On a UNIX system, you can use the (redirected) stdin as it is, and read from keyboard input using FILE *keyboard; keyboard = fopen("/dev/tty", "r"); -- =============== !You!can't!get!here!from!there!rjohnson =============== Feel free to correct me, but don't preface your correction with "BZZT!" Roy Johnson, Shell Development Company