doubt about kernighan and ritchie excercise 1-12
The exercise is to write a program that writes its input one word per line, I did this:
Code:
/* Exercise 1-12. Write a program that prints its input one word per line */
#include <stdio.h>
#define IN 1
#define OUT 0
main()
{
int c;
int state = OUT;
putchar('\n');
putchar('\n');
while((c = getchar()) != EOF){
if((c == ' ' || c == '\t' || c == '\n') && (state == IN)){
putchar('\n');
state = OUT;
}
if(c == '\n')
printf("por fin lo has logrado");
else if((c != ' ') && (c != '\t') && (c != '\n') ){
putchar(c);
state = IN;
}
}
putchar('\n');
putchar('\n');
}
The problem is that when I input a newline (pressing enter), the program shows the output. Why the program is interpreting the -enter- as if I was asking it to evaluate the input instead of interpreting it as a newline? How can I make the program interpret the -enter- as a newline?