Hey this is my code, i want to seperate matrix printing and intialisation into functions as shown (and get then out of main)
however I can't get it to work. I am able to pass 1D arrays but i can't work out 2D matrices
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_CUSTOMERS 100
#define MAX_PRODUCTS 100
void printMatrix( int matrix[][], int rows, int cols )
{ int n, m;
/* Print matrix to check it worked */
for( n=0; n<rows; n++ )
{ printf( "\n" );
for ( m=0; m<cols; m++ )
{ printf(" %d", matrix[n][m] ); }
}
printf( "\n" );
return;
}
void initialiseMatrix( int matrix[][] )
{ int n, m;
/* Set all values to -1 to indicate NOT valid */
for( n=0; n<100; n++ )
{ for ( m=0; m<100; m++ )
{ matrix[n][m]=0; }
}
return;
}
int main()
{
int matrix[MAX_CUSTOMERS][MAX_PRODUCTS];
initialiseMatrix( matrix );
printMatrix( matrix, 100, 100 );
return 1;
}
Thanks