Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site cvl.UUCP Path: utzoo!watmath!clyde!burl!mgnetp!ihnp4!drutx!houxe!hogpc!houti!ariel!vax135!floyd!cmcl2!seismo!rlgvax!cvl!jcw From: jcw@cvl.UUCP Newsgroups: net.micro.pc Subject: Re: strange stdin behavior Message-ID: <1067@cvl.UUCP> Date: Thu, 14-Jun-84 12:05:05 EDT Article-I.D.: cvl.1067 Posted: Thu Jun 14 12:05:05 1984 Date-Received: Fri, 15-Jun-84 02:23:43 EDT References: <2258@ut-sally.UUCP> Organization: U. of Md. Computer Vision Lab Lines: 28 >From: shdanfor@ut-sally.UUCP > >I'm using Microsoft C on a COMPAQ. >Can anybody tell me why the following C program to copy stdin to stdout >doesn't work. (If I do "cpstd < file", each line of file is printed twice.) > >#include>main() >{ > int c; > while ((c = getc(stdin)) != EOF) > putc(c,stdout); >} The stdio routines for your C compiler probably use the buffered keyboard input DOS function call (INT 13?). Even if the input is being redirected, this function call echoes the lines to the screen. Your routine also writes to the screen, so that's why you get them printed twice. If you use a function call that does not echo, then when stdin is not redirected it is confusing to type. A solution would be to use IOCTL to determine if stdin is the console, and use the appropriate function call. I'm not sure if the DOS 2.0 io calls are smarter; I'll try it out. Jay Weber ..!seismo!rlgvax!cvl!jcw ..!seismo!rochester!jay jay@rochester.arpa