Thread: Two-Dimensional Array Initialization (please help)

  1. #1
    Registered User
    Join Date
    Oct 2005
    Windsor, Ontario, Canada

    Two-Dimensional Array Initialization (please help)

    I am a beginnger programmer and I am trying to write a program that will initialize a 2-dimensional array with zeros. Also, it will use a function to do the intializing. Unfortunately I can't get it to work.

    Here is the code I have so far:

    #include <stdio.h>
    #define M 10
    #define N 5
    void InitializeArray2D ( int array[][N], int r, int c);
    void main() 
       int a [M][N];
       InitializeArray2D (a,M,N);
    void InitializeArray2D (int array [][N], int r, int c) {
       int i,j;
       for (i=0; i<r; i++){
            for (j=0; j<c; j++){
                    int array [i][j] = 0;
       printf("%d", array[1][1]); /*test to see if initialization worked*/

    Any help would be greatly appreciated!!

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Sydney, Australia
    In your for loop, remove the "int" from in front of "array". You only need to put the type when declaring the variable.

    Also, main needs to return int, not void.

    Apart from that, it looks fine.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Windsor, Ontario, Canada
    got it working....thanks!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Two Dimensional Array Input from Formatted Data
    By teedoff087 in forum C Programming
    Replies: 14
    Last Post: 04-29-2007, 01:46 AM
  3. Multi dimensional array
    By big146 in forum C++ Programming
    Replies: 4
    Last Post: 06-14-2004, 05:03 PM
  4. 2d arrays in C
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 04-20-2002, 11:09 AM
  5. Replies: 5
    Last Post: 11-20-2001, 12:48 PM