Function to print arbitrary integer array
Hi,
There seems to be a problem with this function which is supposed to print any integer array passed to it.
Code:
void print_int_matrix(int *arb_array,int num_rows,int num_columns)
{
int i,j;
for(i=0;i<num_rows;i++)
{
for(j=0;j<num_columns;j++)
{
printf("%d, ", *(arb_array + (i*num_columns + j)));
}
printf("\n");
}
}
This is printing out some values okay, but some are completely wrong, as if its getting corrupted data. Is there a logical flaw I'm not catching. Also, I'm only using pointer arithmetic here because I couldn't get indexing ( i.e. arb_array[x][y]) to work. Is there a way to use indexing on arrays passed to functions?
Thanks for any input:)