Thread: help with dynamic tic tac toe game (c leng code)

  1. #1
    Registered User
    Join Date
    Aug 2016
    Posts
    4

    help with dynamic tic tac toe game (c leng code)

    hello, i am trying to build a dynamic size tic tac toe game and i have a problam with the switch between player function and getting the move and show the board after the move...
    can you guys help?

    that my code
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    #define SIGN '_'
    #define FIRST 'X'
    #define SECOND 'O'
    
    
    void isValid(void);
    int turn();
    void printMsg();
    
    
    int main()
    {
        printMsg();
        int i, j;//indexs
        int row = 1, column = 1;//first set for the size of the rows\columns.
        char board[row][column];
        do
        {
            scanf("%d", &row);
            column = row;
        }while(row <= 0 || row > 10);
    
    
        for(i = 0; i < row; i++)//for loop to build the board for the game
    
    
          {
    
    
            for(j = 0; j < column; j++)
    
    
             {
                board[i][j] = SIGN;
                printf("%c", board[i][j]);
    
    
             }
    
    
            printf("\n");
        }
        turn();
    
    
      return 0;
    }
    
    
    void printMsg() //prints openning massage.
    {
        printf("Enter board size (1 to 10): \n");
    }
    
    
    int turn(int i, int j)
    {
        int count = 0;
        int player = 0;
        do
        {
        printf("\nplayer %d, enter next move: \n", count % 2 + 1);
        
        }while(i > 0 && j > 0);
        return player;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,602
    > int row = 1, column = 1;//first set for the size of the rows\columns.
    > char board[row][column];
    Your board is fixed at size 1x1, and does not change when you update row and column.

    You trash memory when you try and access out of bounds of your small array.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Memory Allocation - A Simple DOS Text Game
    By pavil in forum C++ Programming
    Replies: 15
    Last Post: 05-12-2014, 06:32 AM
  2. War Card Game with linked lists and dynamic memory
    By jburn09 in forum C Programming
    Replies: 4
    Last Post: 04-24-2013, 01:06 AM
  3. New to dynamic arrays... help with my source code?
    By chubigans in forum C Programming
    Replies: 2
    Last Post: 08-29-2009, 10:41 AM
  4. Please Help - C code creates dynamic HTML
    By Christie2008 in forum C Programming
    Replies: 19
    Last Post: 04-02-2008, 07:36 PM

Tags for this Thread