Thread: passing an array to function

  1. #1
    Registered User
    Join Date
    May 2008

    passing an array to function

    Hi everyone.

    I'm having trouble trying to write a function that takes a two dimensional array as an argument. I want to take a 10 x 10 matrix, and initialise it, so that each element is a '*'.
    I pass an array, that is part of a struct. I'm using the function call:


    where p1 is the struct, and bombBoard is the 10 x 10 array in the struct.

    this is my code

    void initialiseBoard(char *board);
    void initialiseBoard(char *board)
              for(int j= 0; j < 10; j++)
            	 for(int k = 0; k < 10; k++)
               	       *board[j][k] = '*';
    I can't get it to compile. I'm making a mistake with the pointers, I think. Could someone point me in the right direction?

    Thanks in advance,


  2. #2
    The larch
    Join Date
    May 2006
    If you have something like:
    char bombBoard[10][10];
    then the function would take
    void foo(char array[][10]);
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    May 2008
    Thanks for that, problem fixed!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Replies: 7
    Last Post: 11-21-2008, 04:27 PM
  3. function passing argument..array ?
    By jochen in forum C Programming
    Replies: 2
    Last Post: 09-30-2007, 11:53 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM