Note that there are some explanatory texts on larger screens.

plurals
  1. POError when inserting an invalid input
    primarykey
    data
    text
    <p>The expected input is : SET_MINE X Y, while X and Y have to be numbers between 0-19; when the user finishes inserting his data he is expected to write SET_DONE. I'm facing two problems here, which apparently happen due to the same reason: 1. when I insert : SET_MINE (and then press ENTER) or SET_MINE X (inserting only one number rather than two), the line "Insert failed: not enough parameters" is printed on the screen an infinite number of times! 2. The exact same thing happens when I insert numbers out of the range [0,19], e.g: SET_MINE 56 7.Here I'm expecting to see this line on the screen "Insert failed: illegal row/col", but instead I get this one: "Insert failed: not enough parameters" printed an infinite number of times.</p> <p>Here is my code:</p> <pre><code>int main() { int game_board[FIELD_ROWS][FIELD_COLS]={0}; char szLine[MAX_LINE_SIZE]; char* delimiters = " \t\n"; char* pszCommand; char* pszCol; char* pszRow; BOOL gameContinue= TRUE; MINE* pHead = NULL; POSITION pos; int stepDirection; int row=0; int col=0; int old_row=row, old_col=col, mine=0; fgets(szLine,MAX_LINE_SIZE,stdin); // get line from standard input while (strncmp(szLine,"SET_DONE",8) != 0) { pszCommand = strtok(szLine, delimiters); if (NULL == pszCommand ) { continue; } 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; } 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"); continue; } game_board[row][col]=-1; // a mine is inserted to this place } fgets(szLine,MAX_LINE_SIZE,stdin); // get line from standard input } </code></pre> <p>Any ideas?!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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