Test of possible ACSGATE on net

Michael Condict condict at cs.vu.nl
Thu Oct 19 20:11:32 AEST 1989


In article <647 at targon.UUCP> andre at targon.UUCP (andre) writes:
|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?
|    [ Horribly inefficient, unreadable program omitted ]
|I'm going to be flamed for this but...
|
|main(c)
|{
|  while(read(0,&c,1)>0&&(c-' '?write(1,&c,1):1))
|    ;
|}

And well you should be.  All other considerations aside, your version
won't work on machines where &c is the address of the most significant
byte of c, rather than the least significant byte.  On such machines
you read each character into the most significant byte of c, then
(c-' ') compares the least significant byte to ' '.

Michael Condict
Vrije University
Amsterdam



More information about the Comp.lang.c mailing list