Hi, I'm new here and I just need a little help with pointers and 2D arrays. I'm kind of new to programming so this might be redundant. I'm trying to make a 2D array of pointers (already have done) that points to another 2D array of double values... I have the code:

for (i = 0; i < n; i++)
	for (j = 0; j < n; j++)
		ptrA[i][j] = a[j][i];

**its transposed for a reason**

However when I do calculations on array ptrA, it doesnt change the values in array a...

ptrA and a are declared by

double a[n][n];
double temp;
for (i = 0; i < n; i++){			//intializing [A] to inputs
	for (j = 0; j < n; j++){ 
		scanf("%lf", &temp);
		a[i][j] = temp;
	}
}

double **ptrA = malloc(n*sizeof(*ptrA));
if (ptrA != NULL){
	for (i = 0; i < n; i++)
		ptrA[i] = malloc(n*sizeof(*ptrA[i]));
} else return 1;

variable ptrA needs to have three stars

#define maxrows  2
#define maxcols 5


int main()
{
	double a[maxrows][maxcols];
	double ***ptrA = malloc(maxrows * sizeof(double*));
	int i,j;

	for(i = 0; i < maxrows; i++)
	{
		ptrA[i] = malloc(maxcols * sizeof(double*));
		for(j = 0; j < maxcols; j++)
		{
			ptrA[i][j] = &a[i][j];
		}
	}
}

OHHH thank you!
I solved the problem without it anyways... thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.