Test of possible ACSGATE on net
Conor P. Cahill
cpcahil at virtech.UUCP
Mon Oct 16 11:06:38 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))
> ;
> }
If by "tighter" you mean better performing the following would
outdo yours by probably an order of magnitude:
#include <stdio.h>
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 |
+-----------------------------------------------------------------------+
More information about the Comp.lang.c
mailing list