Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8308879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:56:13+00:00 2026-06-08T18:56:13+00:00

So I was working on a Tic-Tac-Toe game and for my input function I

  • 0

So I was working on a Tic-Tac-Toe game and for my input function I was getting the move the player made to store as an integer in a 2d array, the input is gotten using a reference to a 1D array of pointers to positions in the 2D array.

However my problem is, when I seem to set the value of the multi-dimensional array’s square to something by using a pointer, nothing happens.

Here is the input function:

void Game::input(Board b){
int *spots[9]; // Possible spots for the input
bool validInput = false;
spots[0] = &b.board[2][0];
spots[1] = &b.board[2][1];
spots[2] = &b.board[2][2];
spots[3] = &b.board[1][0];
spots[4] = &b.board[1][1];
spots[5] = &b.board[1][2];
spots[6] = &b.board[0][0];
spots[7] = &b.board[0][1];
spots[8] = &b.board[0][2];
redo:
    cout << ">> " << endl;
    int input; // Input
    cin >> input; // Get the input
    validInput = cin;
    if(!validInput){
        cout << "Numbers only please!" << endl;
        cin.clear();
        while(cin.get() != '\n');
        goto redo;
    }
    if(input > 9 || input <= 0){
        cout << "Invalid move!" << endl;
        goto redo;
    }
    input--; // Subtract 1 for array location
    if(*spots[input] != 0){
        cout << "Square is already being used!" << endl;
        goto redo;
    }
    *spots[input] = 1;
}

Now, say I input the number 7. It should set b.board[0][0] to 1. However this doesn’t seem to happen. When I run a unit case afterwards, the board[0][0] doesn’t seem to be set to 1, and it doesn’t reflect in my array. Am I messing something up about pointers here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:56:14+00:00Added an answer on June 8, 2026 at 6:56 pm

    The argument to your function is passed by value and therefore any changes you make to it are not recognized since pass by value creates a copy of the argument. Consider passing by pointer or reference instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have been working on a 2 player Tic-Tac-Toe game in java that
I'm working on making a two player tic-tac-toe game, and am in the phase
I'm working on a tic tac toe game and am wanting to implement an
I have built a two-player tic tac toe game in Java, using sockets (no
Hello I am working on a tic-tac-toe project on my own. I am not
I'm writing a Tic Tac Toe Game and I would like to know how
In the pencil-and-paper game, Tic-tac-toe, 2 players take turns to mark 'X' and 'O'
I have a tic tac toe program and I've got everything working that way
I am making a complex tic tac toe program that has a variable grid
I'm trying to learn C++ and I'm writing a Tic Tac Toe program. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.