i need some help on this. I have the array numbers stored already but the array dosent display on the screen. Why? here is the code

# include <stdio.h>
# include "simpio.h"
# include "genlib.h"
# include "strlib.h"
# include <math.h>
# define size 3

main()
{
      int intArray[size][size];
      
      intArray[0][0]=GetInteger();
      intArray[0][1]=GetInteger();
      intArray[0][2]=GetInteger();
      intArray[1][0]=GetInteger();
      intArray[1][1]=GetInteger();
      intArray[1][2]=GetInteger();
      intArray[2][0]=GetInteger();
      intArray[2][1]=GetInteger();
      intArray[2][2]=GetInteger();    
      void displayMatrix (int intArray[3][3]);   
      getchar();
}

Do you have the displayMatrix function defined anywhere? I dont believe it is a built in function. Supply us with the code for the displayMatrix function so we can see if there is a problem.

OH you need such a function. How would you write a function like that? I just thought you used display matrix. How do your write such a function?

Oh i get it. I wrote one but it says in "value included from C:\Dev-Cpp\Excercises\3X3 array.c"
this is the function

void printMatrix (int intArray[3][3]);  
# define size 3
main()
{
      int intArray[3][3];
      void displayMatrix (int intArray[3][3]); 
      {
           int row,collum;
           for(row=0;row<size;row++)
           {
           for(collum=0;collum<size;collum++)
           {printf("%d",intArray[row][collum]);}
           printf("\n");
           }
}

I got this for the program now, but the array dosen't print properly why?

# define chunk 3  
# include <stdio.h>
# include "simpio.h"
# include "genlib.h"
# include "strlib.h"
void printMatrix (int intArray[3][3])
{
      {
           int row,collum;
           for(row=0;row<chunk;row++)
           {
           for(collum=0;collum<chunk;collum++)
           {printf("%d",intArray[row][collum]);}
           }
      }
}
    




main()
{
      int intArray[chunk][chunk];
      
      intArray[0][0]=GetInteger();
      intArray[0][1]=GetInteger();
      intArray[0][2]=GetInteger();
      intArray[1][0]=GetInteger();
      intArray[1][1]=GetInteger();
      intArray[1][2]=GetInteger();
      intArray[2][0]=GetInteger();
      intArray[2][1]=GetInteger();
      intArray[2][2]=GetInteger();    
      printMatrix(intArray[3][3]);   
      getchar();
      getchar();
}

It doesnt appear that the variable chunk is declared anywhere. It looks like you should be getting compile errors. Are you? If so, tell us what they are.
EDIT

Nevermind that. I see it is defined as a constant. Sorry

Edited 7 Years Ago by Grn Xtrm: n/a

it says "[Warning] passing arg 1 of 'printfMatrix' makes pointer from integer without a cast"

printMatrix(intArray[3][3]);

You need to pass the name of the array, which is a pointer. When you're not defining or declaring an array, arrayname[2][5] is an element in the array, not a pointer to the array.

arrayname => pointer to the first element in the array (or a pointer to the array)
arrayname[0] => first element in the array
arrayname[1] => second element in the array

so wait, have something like this. Case i still got errors. P.S. can you actually show what im supposed to do by rewriting it and posting it on here.

# define chunk 3  
# include <stdio.h>
# include "simpio.h"
# include "genlib.h"
# include "strlib.h"
void printMatrix (int intArray[3][3])
{
      {
           int row,collum,count;
           count=0;
           for(row=0;row<chunk;row++)
           {
           for(collum=0;collum<chunk;collum++)
           {printf("%d    ",intArray[row][collum]);}
           
           }
      }
}
    




main()
{
      int intArray[chunk][chunk];
      
      intArray[0][0]=GetInteger();
      intArray[0][1]=GetInteger();
      intArray[0][2]=GetInteger();
      intArray[1][0]=GetInteger();
      intArray[1][1]=GetInteger();
      intArray[1][2]=GetInteger();
      intArray[2][0]=GetInteger();
      intArray[2][1]=GetInteger();
      intArray[2][2]=GetInteger();    
      printMatrix(intArray[0][0]); 
      printMatrix(intArray[0][1]);
      printMatrix(intArray[0][2]);
      printMatrix(intArray[1][1]);
      printMatrix(intArray[1][0]);
      printMatrix(intArray[1][2]);
      printMatrix(intArray[2][1]);
      printMatrix(intArray[2][0]);
      printMatrix(intArray[2][2]);  
      getchar();
      getchar();
}

You are supposed to give the function printMatrix a pointer to the array which is the name of the array. Not the elements!

This article has been dead for over six months. Start a new discussion instead.