Test of possible ACSGATE on net

Lloyd Kremer kremer at cs.odu.edu
Tue Oct 17 00:27:16 AEST 1989


In article <16103 at nswitgould.cs.uts.oz> garth_kidd%680.808 at fidogate.fido.oz (Garth Kidd) writes:
 
>Can anyone think of a tighter way of coding a filter to strip spaces 
>from the input stream than this?
> 
>main()
>{
>  char ch;
> 
>  for(;read(0,&ch,1)==1;write(1,&ch,(ch==' ')?0:1))
>    ;
>}

Others have mentioned the incredible overhead of 1-byte reads and writes,
but there is another problem with this.  On many systems, a write() of
zero bytes sends EOF.  The reading process may decide to exit after your
first write() of zero bytes.  The result would be to copy the input up to
but not including the first space.

-- 
					Lloyd Kremer
					...!uunet!xanth!kremer
					Have terminal...will hack!



More information about the Comp.lang.c mailing list