2

.h file

@interface GameState :NSObject{
int SymbolsPositions[3][5];
}
-(void)SaveCurrentGameState:(int **)Array;
@end


@interface GameViewController : UIViewController 
{
  ...
 int sequence_after_spin[3][5];
  ...
}
-(Void)AMethod;
@end

.m file

@implementation GameState
-(void)SaveCurrentGameState:(int **)Array
{   
    for(int i = 0;i<5;i++)
     for(int j = 0;j<3;j++)
       NSLog(@" %d",Array[j][i]);
}
 @end


@implimentation GameViewController
-(void)AMethod
 {
   [instanceOfGameState SaveCurrentGameState:sequence_after_spin];
  }
@end

the application crashes when ever AMethod is called iget following warning

warning: incompatible pointer types sending 'int [10][5]' to parameter of type 'int **' [-pedantic]
2
  • Add the crash log too. Crash might be for a different reason. Commented Jul 15, 2011 at 8:12
  • int** and (*int)[5] are not the same Commented Aug 11, 2011 at 8:13

2 Answers 2

5

The argument needs to take an array of int[][5], the reason for this is because the compiler needs to know the number of columns to correctly identify where the members are. You could also specify int[10][5] as the parameter type if you always take the same size array.

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

Comments

0

While there could be other errors, one I see is

for(int i;i<5;i++)
    for(int j;j<3;j++)
        NSLog(@" %d",Array[j][i]);

You are not setting an initial value to i and j. i and j could be any garbage value.

for(int i = 0;i<5;i++)
    for(int j = 0;j<3;j++)
        NSLog(@" %d",Array[j][i]);

Comments

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.