C compilation problem

Discussion in 'Software' started by Computer Acolyte, Jan 1, 2008.

  1. Computer Acolyte

    Computer Acolyte Private First Class

    My code doesn't doesn't compile and I can't figure out why.
    The problem is regarding the three functions I defined. When I try to compile it says the same thing about each three of them in the line where I try to use them: syntax error before token']'. I've gone through my code again and again but as far as I can tell it's all by the book. What am I missing?

    Note in case someone from my university googles this: my ID is 311670137

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    
    /*=========================================================================
      Constants and definitions:
    ==========================================================================*/
    
    #define PLACE 0
    #define MONEY 1
    #define NUM_OF_PLAYERS 2
    #define MAX_LOTTO 40
    #define MAX_TAX 60
    #define MAX_BOARD_SIZE 25
    #define START_MONEY 100
    #define END_GAME -1
    
    /*-------------------------------------------------------------------------
      The main program. (describe what your program does here)
     -------------------------------------------------------------------------*/
    void board_initialization(char board[], int number_of_squares);
    void player_initialization(int players[][2]);
    void display_board(int players[][2], char board[], int number_of_squares);
    /*-------------------------------------------------------------------------
      The main program. (describe what your program does here)
     -------------------------------------------------------------------------*/
    int main() 
    {
        int players[NUM_OF_PLAYERS+1][2];
        char board[MAX_BOARD_SIZE]={0};
        int number_of_squares, turn=1;
        double temp;
        
        printf ("Welcome to Monopole (TM, C, R)!\nThis game is for %d players. \n", NUM_OF_PLAYERS);
        printf ("These are the board game tokens and their meanings: \n");
        printf ("S - Start\nT - Tax\nP - Property for sale\nL - Lottery\n E - Empty place\n");
        printf ("Player's property: 1 - %d\n\nHave fun!\n\nPlease select board legth.\n", NUM_OF_PLAYERS);
        printf ("Enter an integer between 10 and %d: ", MAX_BOARD_SIZE);
        while (1){
              scanf("%lf", &temp);
              while(getchar()!='\n');
              number_of_squares=temp;
              if ((temp-number_of_squares)==0)
                 break;
              else
                  printf("wrong input, try again: ");
        }
        board_initialization(board[], number_of_squares);
        player_initialization(players[][2]);
        while (1){
              display_board(players[][2], board[], number_of_squares);
              system("pause");
        }
        
        
        
        return 0;
    }
    
    void board_initialization(char board[], int number_of_squares){
         int i=1;
         
         board[0]='S';
         for (i; i<number_of_squares; i++){
             if (i%4==0){
                board[i]='T';
                continue;
             }
             if (i%3==0){
                board[i]='P';
                continue;
             }
             if (i%2==0){
                board[i]='L';
                continue;
             }
             board[i]='E'; 
         }
    }
    
    void player_initialization(int players[][2]){
         int i=1;
         
         for (i; i<NUM_OF_PLAYERS; i++){
             players[i][PLACE]=0;
             players[i][MONEY]=START_MONEY;
         }
    }
    
    void display_board(int players[][2], char board[], int number_of_squares){
         int j=1, i=0;
         
         for (i; i<number_of_squares; i++)
             printf(" %c ", board[i]);
         printf("\n");
         for (j; i<NUM_OF_PLAYERS+1; j++)
             for (i=0; i<number_of_squares; i++)
                 if (players[PLACE][j]!=i)
                    printf("   ");
                 else
                     printf("[%d]", j);
    }
     
  2. Wookie

    Wookie Sergeant Major

    The brackets should only be needed when referencing a specific element in the array, not when passing a copy of the variable to a function

    IE try this
    board_initialization(board, number_of_squares);

    instead of
    board_initialization(board[], number_of_squares);

    and you should see one less compile error
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds