M
Mike Copeland
In the program below I'm trying to assign initial values, but I get
runtime errors when I execute it. Specifically, the program aborts
wherever I assign a value to the std::string variables. I used to do
all this (without difficulty) with C-style strings, but when I changed
the code to use std:strings, the code gets runtime errors.
There must be some concept I don't understand here, and I'd
appreciate help in pointing out what I did wrong and how to correct it.
TIA
#include <string>
using namespace std;
struct PHASEREC
{
short phaseType;
short phaseNum;
string phaseDescr;
string phaseTitle;
};
struct DEF_STRUCT
{
string eventName;
PHASEREC Phases[5];
} *Defs[9];
int main()
{
int iii, jjj;
for(iii = 0; iii < 9; iii++)
{
if(Defs[iii] == NULL)
Defs[iii] = (DEF_STRUCT*)malloc (sizeof(DEF_STRUCT));
Defs[iii]->eventName = ""; // << abort here!!
} // for
for(jjj = 0; jjj < 5; jjj++)// initialize Phase info
{
Defs[jjj]->Phases[iii].phaseNum = 0;
Defs[jjj]->Phases[iii].phaseType = 0;
Defs[jjj]->Phases[iii].phaseDescr = ""; // << & here!!
Defs[jjj]->Phases[iii].phaseTitle = ""; // << & here!!
} // for
return true;
}
runtime errors when I execute it. Specifically, the program aborts
wherever I assign a value to the std::string variables. I used to do
all this (without difficulty) with C-style strings, but when I changed
the code to use std:strings, the code gets runtime errors.
There must be some concept I don't understand here, and I'd
appreciate help in pointing out what I did wrong and how to correct it.
TIA
#include <string>
using namespace std;
struct PHASEREC
{
short phaseType;
short phaseNum;
string phaseDescr;
string phaseTitle;
};
struct DEF_STRUCT
{
string eventName;
PHASEREC Phases[5];
} *Defs[9];
int main()
{
int iii, jjj;
for(iii = 0; iii < 9; iii++)
{
if(Defs[iii] == NULL)
Defs[iii] = (DEF_STRUCT*)malloc (sizeof(DEF_STRUCT));
Defs[iii]->eventName = ""; // << abort here!!
} // for
for(jjj = 0; jjj < 5; jjj++)// initialize Phase info
{
Defs[jjj]->Phases[iii].phaseNum = 0;
Defs[jjj]->Phases[iii].phaseType = 0;
Defs[jjj]->Phases[iii].phaseDescr = ""; // << & here!!
Defs[jjj]->Phases[iii].phaseTitle = ""; // << & here!!
} // for
return true;
}