print input one word per line
Hello everyone, I'm a little confused with the code below. It works fine, but I don't understand the concept of checking if "state" is either IN or OUT. for example, in the if statement, "if (c == ' ' || c == '\n' || c == '\t')" this checks if "c" is currently outside of a word, so if this is true, why would it be checking if "c" is == to IN ? IN is suppose to mean that it's inside of a word. Appreciate any help. thanks. #define IN 1 #define OUT 0 int main() { int c, state; state = OUT; while ((c = getchar()) != EOF) { if (c == ' ' || c == '\n' || c == '\t') { if (state == IN) { putchar('\n'); state = OUT; } } else if (state == OUT) { state = IN; putchar(c); } else { putchar(c); } } }