Line 19 is redundant, because flag == 1 anyway.
The case in line 25-27 should be "take no action", not ignore the next character. So, basically, you just need to negate/invert the condition in line 24 and use the else branch as the body of the new if.