Hello Guys and Gals,
I am a new to the forum and haven't used C beyond basic programming before, hence I am still learning and need some help with a particular problem. I am trying to create a data structure that will be partially dimensioned at run time, hence using pointers instead of arrays or malloc functions.
The data structure needs two dimensions, i.e. rows and columns.
The number of columns are defined at run time but the number of rows are not, and as the program runs the number of rows will grow and be added to with sample values.
I am compiling C using the Microchip C30 and MPLAB IDE for PIC microcontrollers. I would be very grateful if you could advise on the method for achieving this, since I run into various compile errors such as pointer not declared, error before = etc.
The sort of code I am using is below:
Code:
//structure declarations
//rows of this struct that can grow
typedef struct rowStruct{
int index;
int value;
}row,*rowPtr;
//columns
typedef int column, *columnPtr;
//combines row and column
struct{
row *rowPtr;
column *columnPtr;
} dataSet, *dataSetPtr
void structInit()
{
int i=1;
//initialise the first row values for each column
while (dataSetPtr->channel<=16) //16 is actually an ext variable
{
dataSetPtr->channel=i;
rowPtr=&(dataSetPtr->row);//get syntax error before '=' here.
rowPtr->Index=0;
rowPtr->value=0;
i++;
}
}
//end
As said I can't get this to compile let alone test the two dimensionality that I need, and there may be much better ways of doing this, any help would be much appreciated!!