Thursday, July 30, 2009

C language Help (dynamic multidimensional array)?

i have this array:


int array[unknown1][unknown2];


how can i place the value of 'unknown1' and 'unknown2' from inputted data. using dynamic multidimensional array.





for example:


printf("Input row size: ");


scanf("%d",%26amp;s1);


printf("Input column size: ");


scanf("%d",%26amp;s2);





using dynamic multidimensional array..


how can i transfer the value of s1 to unknown1 and s2 to unknown2..





really need your help.. thanks!

C language Help (dynamic multidimensional array)?
Something like this:





int **myArray;


int s1,s2,i;





printf("Input row size: ");


scanf("%d",%26amp;s1);


printf("Input column size: ");


scanf("%d",%26amp;s2);





myArray[0] = malloc(s1*s2*sizeof(int));


if (myArray[0] != NULL ) {


for (i = 0;i%26lt;s1,i++) {


myArray[i] = (i * s2) + myArray[0];


}


}





myArray can then be used as normal





myArray[2][4] = 20;


No comments:

Post a Comment