Hello gurus,
I have a code I inherited that is loaded with pointers. Here is my problem. The application is reading a stream file to get the data. There is a delimiter 'xle' or 'xlc' or 'eof' that let the app know when it is at the end of a block. The app uses a 'get(char*, n, c)' function to get the data. However, when the app tries to determine the 'strlen' or 'strcmp' the pointer. I get an Access Violation'. Example below. Please help. Thx.
char IVectrfile::getField(char **saveaddr = NULL)
{
long curloc = tellg();
int n = 0;
bool done = false;
char c;
char *dat;
while ( !done )
{
c = ifstream::get();
if((c == '\x1c') || (c == '\x1d') || (c == '\x1e') || (c == EOF))
done = true;
n++; // count will include the terminator
}
if (n > 1) // data other than the terminator
{
seekg(curloc);
dat = new char[n];
//copy the field to the memory up to the trmator
get(dat, n, c); // end the field with \0
ifstream::get(); // get rid of the terminator
// put the address into saveaddr
*saveaddr = dat;
}
}
...
...
char ** flds = 0;
if (pTf->WantThisData(flds))
{
// if 'all passengers' add it to the pnr ssrlist
// else find the passenger(s) and add it to them
findAndAddData(flds);
}
clear(flds);
...
...
int WantThisData(char ** ssrInfo)
{
/***************************************************
The application fails on the 'if' statement below
***************************************************/
// esrDataNo is a 'typedef enum' value is 6
if ((strlen(ssrInfo[esrDataNo]) > 0)
&& (strcmp(fltno, ssrInfo[esrDataNo])))
return 0;
return 1;
}
I have a code I inherited that is loaded with pointers. Here is my problem. The application is reading a stream file to get the data. There is a delimiter 'xle' or 'xlc' or 'eof' that let the app know when it is at the end of a block. The app uses a 'get(char*, n, c)' function to get the data. However, when the app tries to determine the 'strlen' or 'strcmp' the pointer. I get an Access Violation'. Example below. Please help. Thx.
char IVectrfile::getField(char **saveaddr = NULL)
{
long curloc = tellg();
int n = 0;
bool done = false;
char c;
char *dat;
while ( !done )
{
c = ifstream::get();
if((c == '\x1c') || (c == '\x1d') || (c == '\x1e') || (c == EOF))
done = true;
n++; // count will include the terminator
}
if (n > 1) // data other than the terminator
{
seekg(curloc);
dat = new char[n];
//copy the field to the memory up to the trmator
get(dat, n, c); // end the field with \0
ifstream::get(); // get rid of the terminator
// put the address into saveaddr
*saveaddr = dat;
}
}
...
...
char ** flds = 0;
if (pTf->WantThisData(flds))
{
// if 'all passengers' add it to the pnr ssrlist
// else find the passenger(s) and add it to them
findAndAddData(flds);
}
clear(flds);
...
...
int WantThisData(char ** ssrInfo)
{
/***************************************************
The application fails on the 'if' statement below
***************************************************/
// esrDataNo is a 'typedef enum' value is 6
if ((strlen(ssrInfo[esrDataNo]) > 0)
&& (strcmp(fltno, ssrInfo[esrDataNo])))
return 0;
return 1;
}