Posted By: txesmi
Array dimension error - 01/19/12 16:53
Hi friends,
I have been trying to use a pointer to a multidimensional array but the compiler returns an array dimension error when I try to use the array dimensions with the pointer.
I focused this code to the problem:
I think it should work but i does not. Could someone throw a bit of light to my mixed knowledge? Why does not work?
thanks in advance,
txes
I have been trying to use a pointer to a multidimensional array but the compiler returns an array dimension error when I try to use the array dimensions with the pointer.
I focused this code to the problem:
Code:
#include <acknex.h> int INT_CalculeIndex ( int IndexX, int IndexY ) { return ( (IndexX*8)+IndexY ); } function main () { wait(3); STRING *stemp = str_create ( "" ); int IndexY, IndexX, CalculatedIndex; char CHR_Array[8][8]; char *CHR_Pointer; CHR_Pointer = CHR_Array; for ( IndexX=0; IndexX<8; IndexX++ ) { for ( IndexY=0; IndexY<8; IndexY++ ) { CalculatedIndex = INT_CalculeIndex ( IndexX, IndexY ); // I can assign values to the array with its dimensions CHR_Array[IndexX][IndexY] = CalculatedIndex; // also calculating a unique index CHR_Array[CalculatedIndex] = CalculatedIndex; // I can assign values to the array using the pointer and calculating a unique index CHR_Pointer[CalculatedIndex] = CalculatedIndex; // but not using the array dimensions, compiler returns a dimension of array error //CHR_Pointer[IndexX][IndexY] = CalculatedIndex; } } while ( !key_esc ) { for ( IndexX=0; IndexX<8; IndexX++ ) { for ( IndexY=0; IndexY<8; IndexY++ ) { CalculatedIndex = INT_CalculeIndex ( IndexX, IndexY ); draw_text ( str_for_int(NULL,CHR_Array[CalculatedIndex]), IndexX*30, IndexY*30, COLOR_WHITE ); draw_text ( str_for_int(NULL,CHR_Pointer[CalculatedIndex]), 300+(IndexX*30), IndexY*30, COLOR_WHITE ); draw_text ( str_for_int(NULL,CHR_Array[IndexX][IndexY]), IndexX*30, 300+(IndexY*30), COLOR_WHITE ); // same compiler dimension of array error //draw_text ( str_for_int(NULL,CHR_Array[IndexX][IndexY]), 300+(IndexX*30), 300+(IndexY*30), COLOR_WHITE ); } } wait(1); } sys_exit ( NULL ); }
I think it should work but i does not. Could someone throw a bit of light to my mixed knowledge? Why does not work?
thanks in advance,
txes