title: Occupied Position in Tic-Tac-Toe Game [C]
body: <p>One question about this code: if the choice the player picks is already taken, how do I make him/her choose again?</p>
  
  <p>If I compile the code now, it will change the the position for the one the user chose, and this can't happen.</p>
  
  <p>Obs: the "drawing" of the tic-tac-toe game should appear before this (<code>"\nInform your choice (1-9): "</code>)</p>
  
  <p>This is the code:</p>
  
  <pre><code>char mat[9];
  
  int main(void)
  {
    int i,jogada,casa,jogo=0;
  
    for(i=0; i&lt;= 9; i++) 
      mat[i] = ' ';
  
   do{
    printf("\n");
    printf("\t|\t|\n");
    printf("\t|\t|\n");
    printf("%c\t|%c\t|%c\n",mat[1],mat[2],mat[3]);
    printf("--------|-------|-------\n");
    printf("\t|\t|\n");
    printf("%c\t|%c\t|%c\n",mat[4],mat[5],mat[6]);
    printf("--------|-------|-------\n");
    printf("\t|\t|\n");
    printf("\t|\t|\n");
    printf("%c\t|%c\t|%c\n\n",mat[7],mat[8],mat[9]);
    printf("\nJOGADOR X ");
    printf("\nInforme uma posicao livre (1-9): ");
    scanf("%d",&amp;casa);
    }while((casa&gt;=1)&amp;&amp;(casa&lt;=9));
  
    if((casa&gt;=1)&amp;&amp;(casa&lt;=9))
    {
  
    if(mat[casa] == 'X' || mat[casa] == 'O')
       printf(" ");
    else     
       mat[casa] = 'X';
  
    }      
    printf("\n");
    printf("\t|\t|\n");
    printf("\t|\t|\n");
    printf("%c\t|%c\t|%c\n",mat[1],mat[2],mat[3]);
    printf("--------|-------|-------\n");
    printf("\t|\t|\n");
    printf("%c\t|%c\t|%c\n",mat[4],mat[5],mat[6]);
    printf("--------|-------|-------\n");
    printf("\t|\t|\n");
    printf("\t|\t|\n");
    printf("%c\t|%c\t|%c\n\n",mat[7],mat[8],mat[9]);
  
  
  
    if(mat[1] != ' ' &amp;&amp; mat[1] == mat[2] &amp;&amp; mat[2] == mat[3]) {
                jogo++;
                printf("X Ganhou!\n"); 
                break;  }
         else if(mat[4] != ' ' &amp;&amp; mat[4] == mat[5] &amp;&amp; mat[5] == mat[6]) {
                printf("X Ganhou!\n");
                jogo++;
                break; }
         else if(mat[7] != ' ' &amp;&amp; mat[7] == mat[8] &amp;&amp; mat[8] == mat[9]) {
                printf("X Ganhou!\n");
                jogo++;
                  break; }
         else if(mat[1] != ' ' &amp;&amp; mat[1] == mat[4] &amp;&amp; mat[4] == mat[7]) {
                printf("X Ganhou!\n");
                jogo++; 
                  break;}
         else if(mat[2] != ' ' &amp;&amp; mat[2] == mat[5] &amp;&amp; mat[5] == mat[8]) {
                printf("X Ganhou!\n");
                jogo++;
                  break; }
         else if(mat[3] != ' ' &amp;&amp; mat[3] == mat[6] &amp;&amp; mat[6] == mat[9]) {
                printf("X Ganhou!\n");
                jogo++;
                  break; }
         else if(mat[1] != ' ' &amp;&amp; mat[1] == mat[5] &amp;&amp; mat[5] == mat[9]){ 
                 printf("X Ganhou!\n");
                jogo++; 
                  break;}
         else if(mat[7] != ' ' &amp;&amp; mat[7] == mat[5] &amp;&amp; mat[5] == mat[3]) { 
                 printf("X Ganhou!\n"); 
                jogo++;
                  break; }
         else if((mat[1] != ' ') &amp;&amp; (mat[2] != ' ') &amp;&amp; (mat[3] != ' ') &amp;&amp; (mat[4] != ' ') &amp;&amp; (mat[5] != ' ') &amp;&amp; (mat[6] != ' ') &amp;&amp; (mat[7] != ' ') &amp;&amp; (mat[8] != ' ') &amp;&amp; (mat[9] = ' ')){
                  printf("Velha!\n");
                  jogo++;
                  break;
                  }
  
       printf("\nJOGADOR O ");
       printf("\nInforme uma posicao livre (1-9): ");
       scanf("%d",&amp;casa);
       if((casa&gt;=1)&amp;&amp;(casa&lt;=9))
       {
  
       if(mat[casa] == 'X' || mat[casa] == 'O')
       ;
       else     
          mat[casa] = 'O';
  
       }            
       printf("\n");
       printf("\t|\t|\n");
       printf("\t|\t|\n");
       printf("%c\t|%c\t|%c\n",mat[1],mat[2],mat[3]);
       printf("--------|-------|-------\n");
       printf("\t|\t|\n");
       printf("%c\t|%c\t|%c\n",mat[4],mat[5],mat[6]);
       printf("--------|-------|-------\n");
       printf("\t|\t|\n");
       printf("\t|\t|\n");
       printf("%c\t|%c\t|%c\n\n",mat[7],mat[8],mat[9]);
  
  
         if(mat[1] != ' ' &amp;&amp; mat[1] == mat[2] &amp;&amp; mat[2] == mat[3]) {
                printf("O Ganhou!\n");  
                jogo++;
                  break; }
         else if(mat[4] != ' ' &amp;&amp; mat[4] == mat[5] &amp;&amp; mat[5] == mat[6]) {
                printf("O Ganhou!\n");
                jogo++;
                  break; }
         else if(mat[7] != ' ' &amp;&amp; mat[7] == mat[8] &amp;&amp; mat[8] == mat[9]) {
                printf("O Ganhou!\n");
                jogo++;
                  break; }
         else if(mat[1] != ' ' &amp;&amp; mat[1] == mat[4] &amp;&amp; mat[4] == mat[7]) {
                printf("O Ganhou!\n");
                jogo++;
                  break; }
         else if(mat[2] != ' ' &amp;&amp; mat[2] == mat[5] &amp;&amp; mat[5] == mat[8]) {
                printf("O Ganhou!\n");
                jogo++; 
                  break;}
         else if(mat[3] != ' ' &amp;&amp; mat[3] == mat[6] &amp;&amp; mat[6] == mat[9]) {
                printf("O Ganhou!\n");
                jogo++;
                  break; }
         else if(mat[1] != ' ' &amp;&amp; mat[1] == mat[5] &amp;&amp; mat[5] == mat[9]){ 
                 printf("O Ganhou!\n");
                jogo++; 
                  break;}
         else if(mat[7] != ' ' &amp;&amp; mat[7] == mat[5] &amp;&amp; mat[5] == mat[3]) { 
                 printf("O Ganhou!\n"); 
                jogo++;
                  break; }
        else if((mat[1] != ' ') &amp;&amp; (mat[2] != ' ') &amp;&amp; (mat[3] != ' ') &amp;&amp; (mat[4] != ' ') &amp;&amp; (mat[5] != ' ') &amp;&amp; (mat[6] != ' ') &amp;&amp; (mat[7] != ' ') &amp;&amp; (mat[8] != ' ') &amp;&amp; (mat[9] = ' ')){
                  printf("Velha!\n");
                  jogo++;
                  break;
                  }
  
  }
  
    system("PAUSE");  
    return 0;
  }
  </code></pre>