1

I'm trying to pass a multi array (for example 3x3) to be printed in a matrice type form using Objective C. I'm fairly new to the language and am stuck. I can pass a single array, however with multi arrays I get the error Array type has incomplete element type.

void printMat(float value[][], int rows, int col)
{
    int j, k;
    float printpt;

    //Handles coloum printing
    for (k=0; k<col; k++)
    {
        NSLog(@"/n");
    //Handles row printing
    for (j=0; j<rows; j++)
    {
        printpt = value[j][k];
        NSLog(@"%f ", printpt);
    }
    }
}

I'm trying to call the function with

printMat(A, n, n)

Where A is the float A[30][30] and n=30. What the best way to achieve this or to pass multi dimensional arrays?

2 Answers 2

2

pass it as float *value, then calculate the offset into the array appropriately. value[j*cols+k].

Note: data is held in the following order - first row (all), second row (all) etc)).

value[] is not incomplete because it behaves as value*.

However, value[][] is incomplete, because it has no way to understand the first [] array subscript without knowing the dimension of the second. For the same reason the statement value[j][k] makes no sense - without knowing the rowsize, how can you address the columns?

float value[][30] works fine, but won't help you because you want to supply a variable size.

Sign up to request clarification or add additional context in comments.

1 Comment

'float value **' or 'float **value'?
1

well for one thing this is not objective-C (with the exception of the NSLog statements) .... in objective-c you would simply create the arrays like so:

NSArray *row1 = [NSArray  arrayWithObjects:obj1,obj2,obj3,nil];
NSArray *row2 = [NSArray  arrayWithObjects:obj3,obj4,obj5,nil];

NSArray *matrix  = [NSArray arrayWithPjects:row1,row2,nil];

and then you function prototype would simply be:

-(void) printMat:(NSArray *)matrix;

2 Comments

arrayWithPjects? I guess thats a typo.
The main reason I avoided NSArray was due to being application requiring up to 40x40 matrices (signal processing).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.