Jun 11, 2002 #1 Mandrill IS-IT--Management Sep 13, 2002 1 US How to allocate a X-dimensional array? X greater than 1.
Jun 11, 2002 #2 dickiebird Programmer Feb 14, 2002 758 GB See thread205-262672 Dickie Bird db@dickiebird.freeserve.co.uk Upvote 0 Downvote
Jun 11, 2002 1 #3 Leibnitz Programmer Apr 6, 2001 393 CA you might also try this: #include<stdio.h> #include<stdlib.h> #define _MAXSIZE_ 100 typedef int RowArray[_MAXSIZE_]; void main() { int ROW, COL; int i, j, k; RowArray *array; /*declaration of the array*/ k = 1; /* input the array */ printf("Array input\n" printf("Enter the value for the \"ROW\": " scanf("%d",&ROW); printf("Enter the value for \"COL\": " scanf("%d",&COL); /*allocate memory for the array*/ array = ( RowArray * )malloc(ROW * COL * sizeof(int)); /*input the array*/ for( i = 0; i < ROW; i++ ) { for( j = 0; j < COL; j++ ) { printf("value%d = ", k ); scanf("%d",&array[j]); k++; } } /* output the array*/ printf("\nArray output\n" for( i = 0; i < ROW; i++ ) { for( j = 0; j < COL; j++ ) { printf("array[%d][%d] = %d\n", i, j, array[j]); } } } Upvote 0 Downvote
you might also try this: #include<stdio.h> #include<stdlib.h> #define _MAXSIZE_ 100 typedef int RowArray[_MAXSIZE_]; void main() { int ROW, COL; int i, j, k; RowArray *array; /*declaration of the array*/ k = 1; /* input the array */ printf("Array input\n" printf("Enter the value for the \"ROW\": " scanf("%d",&ROW); printf("Enter the value for \"COL\": " scanf("%d",&COL); /*allocate memory for the array*/ array = ( RowArray * )malloc(ROW * COL * sizeof(int)); /*input the array*/ for( i = 0; i < ROW; i++ ) { for( j = 0; j < COL; j++ ) { printf("value%d = ", k ); scanf("%d",&array[j]); k++; } } /* output the array*/ printf("\nArray output\n" for( i = 0; i < ROW; i++ ) { for( j = 0; j < COL; j++ ) { printf("array[%d][%d] = %d\n", i, j, array[j]); } } }