![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Registered User Join Date: Sep 2009
Posts: 13
| Is it possible to determine amount of rows of a 2-d array passed in a function Is there a way to do this? (I do know the columns) Code: void printer(int [][3]);
int main(void)
{
int array1[][3]={{ 5,9, 0},
{14,7,13},
{ 2,10,8}};
int array2[][3]={{ 5,9, 0},
{14,7,13},
{55,10,9}
{ 2,10,8}};
printer(array1);
printer(array2);
}
void printer(int ary[][3])
{
int rows = ////// some way to calculate 3 from first instance and 4 for second instance, I have tried sizeof(array)/sizeof(int) but it only calculates the size of the address of array(0Xff244da) */
}
Last edited by hugo2x; 11-10-2009 at 04:55 PM. |
| hugo2x is offline | |
| | #2 |
| Registered User Join Date: Apr 2006
Posts: 1,193
| If by rows you mean the first dimension of the array, that is omitted from the deceleration, then there is no way given the prototype. You can do this: Code: void printer(int (*ary)[4][3])//pointer to 4x3 array
{
int cols = sizeof(**ary)/sizeof(***ary);
/*size of each row devided by the size of each element in each row. (sizeof(***ary)==sizeof(int))
cols should equal 3.*/
int rows = sizeof(*ary)/sizeof(**ary);
/*This computes the size of the whole array divided by the size of each row.
rows should equal 4.*/
(*ary)[1][1]=5;/*this is how to access the array. */
ary[0][1][1]=5;/*this is also valid */
}
__________________ It is too clear and so it is hard to see. A dunce once searched for fire with a lighted lantern. Had he known what fire was, He could have cooked his rice much sooner. Last edited by King Mir; 11-10-2009 at 05:24 PM. |
| King Mir is offline | |
| | #3 |
| Registered User Join Date: Sep 2006
Posts: 2,502
| Could you just pass both dimensions? There had to be a variable for the rows when you put the data into the array. |
| Adak is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Screwy Linker Error - VC2005 | Tonto | C++ Programming | 5 | 06-19-2007 02:39 PM |
| Calling a Thread with a Function Pointer. | ScrollMaster | Windows Programming | 6 | 06-10-2006 08:56 AM |
| <Gulp> | kryptkat | Windows Programming | 7 | 01-14-2006 01:03 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C Programming | 3 | 03-04-2005 02:46 PM |
| Hi, could someone help me with arrays? | goodn | C Programming | 20 | 10-18-2001 09:48 AM |