counting loop operator for
<p>I have to count the <em>for</em> operators that a person writes in the console, but I have to exclude the ones that are in comments - <em>//for</em> and <em>/*for</em> shouldn't be counted.
Also the for's that are inside a multiline comment shouldn't be counted (until it is closed with <em>*/</em>)</p>

<p>Here is what I've tried so far:</p>

<pre><code>int flagcomment = 0;
char *pointerLine;
char string[130];
pointerLine = strtok(string, " (\t\n\b\r{}\\\'\";:)&amp;^%$#@!~-+,.][_=");
while (pointerLine != 0)
{
    printf("%d",flagcomment);
    if (*pointerLine == '/' &amp;&amp; *(pointerLine + 1) == '/')
        break;
    if (*pointerLine == 'for' &amp;&amp; *(pointerLine + 1) == '"')
        break;
    if (*pointerLine == 'for' &amp;&amp; *(pointerLine + 1) == '/')
        break;
    if (*pointerLine == '/' &amp;&amp; *(pointerLine + 1) == '*' &amp;&amp; (!flagcomment)) 
    { 
        flagcomment = 1; 
        break;
    }
    if (flagcomment==1)
    {
        if (*pointerLine == '*' &amp;&amp; *(pointerLine + 1) == '/') 
        {
            flagcomment = 0;
            break;
        }
        break;
    } 
</code></pre>

<p>It only works sometimes - When I write <em>/*for</em> it stops counting them , but when it comes to end the multiline comment I write <em>for*/</em> but the for's I write after that are still uncounted, but it think that the flag should be 0 when it finds <em>*/</em>. I can't understand why this isn't working, I would be grateful if someone helps me :)</p>