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

Roy Johnson rjohnson at shell.com
Thu Apr 25 02:54:23 AEST 1991


In article <1010 at dri500.dri.nl> heinhuis at dri.nl (Gustaaf-Jan Heinhuis) writes:
>In article <1991Apr23.075320.9473 at en.ecn.purdue.edu> 
>tenka at 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



More information about the Comp.lang.c mailing list