looking for exercise 1-9 from the K&R book (Copy input to output. Replace each string of multiple spaces with one single space) I found this code on this site.
#include <stdio.h>
main()
{
int ch, lch;
for(lch = 0; (ch = getchar()) != EOF; lch = ch)
{
if (ch == ' ' && lch == ' ')
;
else
putchar(ch);
}
}
The program works, but the operation is not clear to me: what is the variable lch for? Why not inserting it inside the third condition of for loop and if statement the program does not give the correct output?