I've realised that my array of structs was being destroyd once the program finishes with the constructor. I've fixed that same way you did.
Code:
class FSAD //Fixed/Selectable Analog Data
{
public:
char Name[25];
int nExpected; // size = nExected*2+1
DataLine *pDataSec;
void MakeSec(DataLine *pDataSec)
{
pDataSec = new DataLine[nExpected*2+1];
}
};
I think the problem comes from the way I pass it to a function. I'm writing a function to fill the array of structs. and I'm not sure how to pass the class to it correctly:
Code:
void ReadDataSec(FILE * inp, FSAD Section , int nExpected)
{
char line[100];
int i=0;
while ( fgets(line, sizeof line, inp) != NULL ) // reads in a line of text from file
{
//if ( strncmp(line, "ENDL", 4) == 0 ) // Exit if at the end of a section
//{
sscanf(line, "%s", Section.pDataSec[i].Param);
printf("%s \n", Section.pDataSec[i].Param);
break;
}
//}
}
If I don't use a function, and reference the array of stucts like this:
Code:
strncpy(FAD.pDataSec[0].Param, "something", 20);
printf("%s\n", FAD.pDataSec[0].Param);
I get an run-time error that the memory could not be written.