Hello guys, I'm a beginner in programming. I've just come across the problem in K&R2: Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.I also found a solution, but i have some questions about it. First: what does it mean "inspace=0 ?" what is done by this? and what does " inspace=1" mean? How does the program affect blanks? i have questions about the second solution. what does it mean at the end "pc=c"? for what reason is it used? and could you explain why we take "pc=EOF"? what happens with this assignment? Sorry for my easy questions, but i really could not find answers to these.
Code:
#include <stdio.h>
/* count lines in input */
int
main()
{
int c, pc; /* c = character, pc = previous character */
/* set pc to a value that wouldn't match any character, in case
this program is ever modified to get rid of multiples of other
characters */
pc = EOF;
while ((c = getchar()) != EOF) {
if (c == ' ')
if (pc != ' ') /* or if (pc != c) */
putchar(c);
/* We haven't met 'else' yet, so we have to be a little clumsy */
if (c != ' ')
putchar(c);
pc = c;
}
return 0;
}