In your first example
if(c != ' ')
putchar(c);
lastspace = 0;
doesn't place {}
braces after the if
statement so only the immediate following statement is executed conditionally. Changing indentation and adding braces shows that the code is actually
if(c != ' ') {
putchar(c);
}
lastspace = 0;
This is the reason why some coding standards mandate the use of {}
following all control statements.