Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!virtech!cpcahil From: cpcahil@virtech.UUCP (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: Test of possible ACSGATE on net Message-ID: <1282@virtech.UUCP> Date: 16 Oct 89 01:06:38 GMT References: <16103@nswitgould.cs.uts.oz> Organization: Virtual Technologies Inc Lines: 39 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)) > ; > } If by "tighter" you mean better performing the following would outdo yours by probably an order of magnitude: #include main() { int ch; while( (ch=getchar()) != EOF) { if( ch != ' ' ) { putchar(ch); } } } Actually, my "order of magnitude" estimation is incorrect. Processing 90K of data using your program took 53 seconds of cpu time, while the example I gave took .4 seconds (more like 2 orders of magnitude). -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+