Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!uakari.primate.wisc.edu!xanth!kremer From: kremer@cs.odu.edu (Lloyd Kremer) Newsgroups: comp.lang.c Subject: Re: Test of possible ACSGATE on net Summary: writes of zero bytes can send EOF Message-ID: <10198@xanth.cs.odu.edu> Date: 16 Oct 89 14:27:16 GMT References: <16103@nswitgould.cs.uts.oz> Organization: Old Dominion University, Norfolk, Va. Lines: 24 In article <16103@nswitgould.cs.uts.oz> garth_kidd%680.808@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!