Keep a state when parsing text
<p>I'm trying to make a program that looks for syntax and everytime it goes from state to state
It needs to indicate that state. I'm getting different output that I shouldn't have got.</p>

<pre><code>using namespace cppfsm;
#include &lt;vector&gt;
#include &lt;iostream&gt;

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int cppfsm::updateState(int&amp; state, char c) {
    const int state1 = 1;
    const int state2 = 2;

    switch (state) {
    case state1:
        if (c == '/')
            cout &lt;&lt; "1" &lt;&lt; endl;
            // do stuff; update state
        else if (c == '"')
            cout &lt;&lt; "1" &lt;&lt; endl;
            // do something else; update state

    case state2:
        if (c == '/')
            cout &lt;&lt; "1" &lt;&lt; endl;
            // do stuff; update state
        else if (c == '"')
            cout &lt;&lt; "1" &lt;&lt; endl;
            // do something else; update state

    }
    return 0;
}

void testFSM(string s) {
    vector&lt;int&gt; stlist; // list of states.
    int cstate = start;
    for (unsigned long i = 0; i &lt; s.length(); i++) {
        stlist.push_back(updateState(cstate,s[i]));
    }
    // push the last state:
    stlist.push_back(cstate);
    cout &lt;&lt; s &lt;&lt; endl;
    for (unsigned long i = 0; i &lt; stlist.size(); i++) {
        cout &lt;&lt; stlist[i];
    }
    cout &lt;&lt; endl;
}

int main() {
    // the finite state machine:
    string input;
    while(getline(cin,input)) {
        cout &lt;&lt; " ";
        testFSM(input);
    }
    return 0;
}
</code></pre>

<p>the output should be looking like this.
the numbers are the states when going from 1 to another</p>

<pre><code>$ echo "int x; // holds stuff" | ./fsm 
int x; // holds stuff
0111010042222222222222
$ echo 'cout &lt;&lt; "some string";' | ./fsm 
cout &lt;&lt; "some string";
01111000033333333333300
$ echo 'cout &lt;&lt; "\"escape\" chars are fun";' | ./fsm 
cout &lt;&lt; "\"escape\" chars are fun";
011110000353333333533333333333333300
</code></pre>

<p>But my output comes out to be all 0000......s. How do I fix this problem?</p>
