Thread: question from a newbie

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    2

    question from a newbie

    Hi. Sorry to bother you guys with this newbie problem I'm having. I'm trying to learn C by trying to create a tic-tac-toe game. This is my code so far:

    Code:
    #include <stdio.h>
    
    #define ROWS 3
    #define COLUMNS 3
    
    void initialize_board(void);
    void test(void);
    
    int board[ROWS][COLUMNS];
    
    int main() {
        initialize_board();
    
        test();
    
        return 0;
    }
    
    void initialize_board(void) {
        int i, j;
        extern int board[][];
    
        for (i = 0; i < ROWS; ++i)
            for (j = 0; j < COLUMNS; ++j)
                board[i][j] = 0; // compiler error here!
    }
    
    void test(void) {
        int i, j;
        extern int board[][];
    
        for (i = 0; i < ROWS; ++i)
            for (j = 0; j < COLUMNS; ++j)
                printf("board[%d][%d] = %d", i, j, board[i][j]); // compiler error here!
    }
    The problem is that the compiler complains about "invalid use of array with unspecified bounds". I do not know how to fix the compiler errors. Can anyone show me what I'm doing wrong?

  2. #2
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Perhaps, instead of "++i", try "i++" - the switcharoo with the plus signs and the i. The same for the j variable.
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    2
    Quote Originally Posted by ulillillia View Post
    Perhaps, instead of "++i", try "i++" - the switcharoo with the plus signs and the i. The same for the j variable.
    I feel so stupid...the simple remedy was to remove the "extern" declarations. Thanks for the feedback though.

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by yoda05378 View Post
    I feel so stupid...the simple remedy was to remove the "extern" declarations. Thanks for the feedback though.
    Yes, Was about to say that, they're infact compiled in the same module hence no 'extern' keyword needed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 06:45 PM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  4. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 04:09 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM