#include #include #include #include enum state {TOP, ERROR}; int main(void) { // initial state is outside of any tag, and not inside any elements // of interest enum state curr = TOP; int ch; while ((ch = fgetc(stdin)) != EOF) { // one case in the switch per state switch (curr) { case TOP: // what do we do when outside any tag and we see ch? break; // define cases for additional states you define here case ERROR: // we can send things here as a precaution when things // are in the wrong place and then keep doing nothing // until the end of file break; } } }