I am trying to print all the values in a two dimensional array. I come from Java and I'm having issues figuring this out in C. How do you access the value at two given indices in C?
void PrintArrayByPointer(int *ptrToArray)
{
int i,j;
printf("\nPrint Array By Pointers: \n");
for(i=0; i<ROWS; i++)
{
for(j=0; j<COLS; j++)
{
// print the value here
}
printf("\n");
}
return;
}
i*COLS+jptrToArray.doubleandROWS&COLSare declared global .........printf("%f",&ptrToArray[i*ROWS + j])insidej-loop.ptrToArray[i][j]to work, because there is no way to know the length of each row.ptrToArraypoints to a 1-D array.