I have an array of integers:
int* list = malloc((m*n) * sizeof(int)); Variables m and n are the required dimensions of a 2d array.
I filled my array with random numbers and printed it with a simple for (int i = 0; i < lines; i++) printf("%d\n", list[i]); Which prints:
4
5
100
7
9
3
74
1
6
My question is how can I print the array as a 2d array instead of 1d?
Here's my attempt:
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
printf("%d", list[i]);
}
printf("\n");
}
But this prints first n numbers like this:
444
555
100100100
Leaving the rest of the array lost somewhere.
list[i]->list[i*m+j].