| | |
Hwk: how do I make a 2d array of pointers point to another array
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 6
Reputation:
Solved Threads: 0
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:
**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
C Syntax (Toggle Plain Text)
for (i = 0; i < n; i++) for (j = 0; j < n; j++) ptrA[i][j] = a[j][i];
However when I do calculations on array ptrA, it doesnt change the values in array a...
ptrA and a are declared by
C Syntax (Toggle Plain Text)
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;
Last edited by Tamaki; 20 Days Ago at 2:20 pm.
-7
#2 19 Days Ago
variable ptrA needs to have three stars
C Syntax (Toggle Plain Text)
#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]; } } }
Last edited by Ancient Dragon; 19 Days Ago at 11:39 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Array of pointers (C++)
- Adding an array to an element of the array (C++)
- Passing 2D Array of Pointers into a function (C++)
- Usage of array of pointers (C++)
- read line of text from file into array (C++)
- Array of pointers to structure (C)
- Array of pointers to objects (C++)
Other Threads in the C Forum
- Previous Thread: c langauge 2nd edition
- Next Thread: need help!!! to fix my program please!!!
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile createprocess() csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open openwebfoundation owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h






