Thread: Syntax for functions

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2010
    Location
    Australia
    Posts
    174

    Syntax for functions

    I have a couple of errors in my code (which I'll shorten for reading convenience). I think it's merely because I'm still quite new to the way functions are expressed

    Code:
    void printBoard(int size, int align, int board[size][size]);
    
    int main(int argc, char *argv[]) {
        int board[MAX][MAX] = {{}}; // intialized elements to zero
        int size = 0;
        int align = 0;
        
       printBoard(size, align, board[MAX][MAX]);
    
       return 0;
    }
    
    void printBoard(int size, int align, int board[size][size]) {
        int i,j;
    
        for (i=0; i<size; i++) {
            for (j=0; j<size; j++) {
                printf("%*d", align, board[i][j]);
            }
        }
    }
    The lines with errors are in red. What am I doing wrong? And in this code I have that size <= MAX depending on the user input for size, so should I be sending board[size][size] to the printBoard function or should I be sending board[MAX][MAX] since my loops are only going to be dealing with a size*size array anyway.

    EDIT: The errors I'm getting are,
    for first line of error - note: expected ‘int (*)[(unsigned int)(size)]’ but argument is of type ‘int’
    second line - error: passing argument 3 of ‘printBoard’ makes pointer from integer without a cast
    Last edited by Mentallic; 08-25-2011 at 11:46 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Syntax for Declaring Functions in Dev-C++
    By Muz in forum C Programming
    Replies: 4
    Last Post: 07-03-2007, 04:53 AM
  2. Syntax Help, class interactions and functions..
    By Shamino in forum C++ Programming
    Replies: 18
    Last Post: 05-17-2007, 01:09 PM
  3. Replies: 3
    Last Post: 10-31-2006, 02:15 AM
  4. Geometry-shapes functions' syntax ?
    By bigjoke in forum C Programming
    Replies: 9
    Last Post: 01-01-2006, 10:25 PM
  5. Replies: 1
    Last Post: 01-20-2002, 11:50 AM