Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is because you are using <code>continue</code> so your second <code>fgets</code> is never executed. See the standard: <a href="http://msdn.microsoft.com/en-us/library/6e3dc2z3.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/6e3dc2z3.aspx</a> (Microsoft's site, but still applicable)</p> <p>Think of the <code>continue</code> statement like telling the loop "Okay, this iteration is done, start the next one."</p> <p>So when you reach the part where you tell the user they didn't supply enough parameters, this is all that the loop sees: </p> <pre><code>fgets(szLine,MAX_LINE_SIZE,stdin); // get line from standard input while (strncmp(szLine,"SET_DONE",8) != 0) { ...; if (0 == strcmp(pszCommand, "SET_MINE")) { pszRow = strtok(NULL, delimiters); pszCol = strtok(NULL, delimiters); if (NULL == pszCol || NULL == pszRow) { fprintf(stderr, "Insert failed: not enough parameters\n"); continue; } } //nothing down here } </code></pre> <p>In the eyes of the program, the second <code>fgets</code> at the bottom of the loop doesn't exist.</p> <p>You can fix this by using more clever conditional logic.</p> <p>This (untested) code snippet should fix things:</p> <pre><code>while (strncmp(szLine,"SET_DONE",8) != 0) { pszCommand = strtok(szLine, delimiters); if (pszCommand != NULL &amp;&amp; 0 == strcmp(pszCommand, "SET_MINE")) { pszRow = strtok(NULL, delimiters); pszCol = strtok(NULL, delimiters); if (NULL != pszCol &amp;&amp; NULL != pszRow) { row = atoi(pszRow); col = atoi(pszCol); if (row &lt; 0 || row &gt;= FIELD_ROWS || col &lt; 0 || col &gt;= FIELD_COLS) { fprintf(stderr, "Insert failed: illegal row/col \n"); } else { game_board[row][col]=-1; // a mine is inserted to this place } } else{ fprintf(stderr, "Insert failed: not enough parameters\n"); } } fgets(szLine,MAX_LINE_SIZE,stdin); // get line from standard input } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload