Test of possible ACSGATE on net

David Goodenough dg at lakart.UUCP
Wed Oct 18 00:35:08 AEST 1989


garth_kidd%680.808 at fidogate.fido.oz (Garth Kidd) sez:
>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))
>    ;
>}

#include <stdio.h>
main()
 {
    int ch;
    while ((ch = getchar()) != EOF)
      if (ch != ' ')
	putchar(ch);
 }

However, contemplate what will happen to the correctness of either of
the above programs if passed through such a filter. They will _BOTH_
break, either failing to compile or generating incorrect code if they
do compile.
-- 
	dg at lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp at xait.xerox.com			  +---+



More information about the Comp.lang.c mailing list