MIPI_BaseC_WebinarFRTK/06_Lecture06/15_fsm_2_p41.c

32 lines
827 B
C
Raw Permalink Normal View History

2024-11-13 09:22:28 +03:00
#include <stdio.h>
int main() {
enum states { before, inside, after } state;
int c;
state = before;
while ((c = getchar()) != EOF) {
switch (state) {
case before:
if (c == '\n')
putchar('\n');
else if (c != ' ')
putchar(c), state = inside;
break;
case inside:
switch (c) {
case ' ':
state = after; break;
case '\n':
putchar('\n'), state = before;
break;
default: putchar(c);
}
break;
case after:
if (c == '\n')
putchar('\n'), state = before;
}
}
return 0;
}