learn_c/intro/ex1_12.c

33 lines
602 B
C
Raw Normal View History

2023-11-13 18:18:50 +00:00
#include <stdio.h>
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
/* count lines, words and characters in input */
main()
{
int c, state;
state = OUT;
while((c = getchar()) != EOF) {
// if (c == ' ' || c == '\t' || c == '\n')
// state = OUT;
// else if (state == OUT) {
// putchar('\n');
// state = IN;
// putchar(c);
// }
// else
// putchar(c);
if (c != ' ' && c != '\t' && c != '\n') {
if (state == OUT)
state = IN ;
putchar(c) ;
}
else if (state == IN) {
state = OUT ;
putchar('\n') ;
}
}
}