Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi-Dimensional Arrays 1

Status
Not open for further replies.

Mandrill

IS-IT--Management
Sep 13, 2002
1
US
How to allocate a X-dimensional array?
X greater than 1.
 
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(&quot;Array input\n&quot;);
printf(&quot;Enter the value for the \&quot;ROW\&quot;: &quot;);
scanf(&quot;%d&quot;,&ROW);
printf(&quot;Enter the value for \&quot;COL\&quot;: &quot;);
scanf(&quot;%d&quot;,&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(&quot;value%d = &quot;, k );
scanf(&quot;%d&quot;,&array[j]);
k++;
}
}
/* output the array*/
printf(&quot;\nArray output\n&quot;);
for( i = 0; i < ROW; i++ )
{
for( j = 0; j < COL; j++ )
{
printf(&quot;array[%d][%d] = %d\n&quot;, i, j, array[j]);
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top