I'm writing a data parsing utility and am coming unstuck (spectacularly) when I try to parse a keyword set.
I have a struct as follows for a keyword group :
In my main parse fnt I do :
The function getkeywords is implemented as follows :
This falls apart when allocating new the third time (the third line of the keyword group). I assume I am doing something silly or corrupting the heap in some way but just cant see it and am now in zombie zone with this one. Is what I am passing through correct ? Any help at all would be appreciated..
Many Thx.
I have a struct as follows for a keyword group :
Code:
// Keyword Bin :
struct KEYWORDBIN
{ INT keywordindex;
CHAR name[MAX_STR_SIZE];
BOOL iscasesensitive;
COLOUR colour;
CHAR *keywords[];
};
In my main parse fnt I do :
Code:
KEYWORDBIN *kwd = new KEYWORDBIN;
if (getkeywords(fp,kwd->keywords) == 0)
return FALSE;
The function getkeywords is implemented as follows :
Code:
INT DATACOLLECTOR::getkeywords (FILE *fp, CHAR *keywords[])
{ CHAR *keygroupdelims[2] = {"/K","/EOL"};
CHAR delims[2] = {' ','\n'};
CHAR *lptr = NULL;
INT j = 0;
BOOL go = TRUE;
// Get the first line and set the pointer :
fgets(linerecord,MAX_LINE_LENGTH,fp);
lptr = linerecord;
// Check if we go:
for (INT i=0; i<2; ++i)
{ if (strstr(linerecord, keygroupdelims[i]) != NULL)
go = FALSE;
}
while (go)
{ // Scan and lift all keywords on the line :
do
{ CHAR *newkwd = new CHAR[MAX_KWD_LENGTH];
getdelimitedstr(&lptr,newkwd,delims,MAX_KWD_LENGTH);
keywords[j++] = newkwd;
} while (skipspaces(&lptr) && *lptr != '\n');
// Get the next line and reset the pointer :
if (!feof(fp))
{ fgets(linerecord,MAX_LINE_LENGTH,fp);
// Check if we go:
for (INT i=0; i<2; ++i)
{ if (strstr(linerecord, keygroupdelims[i]) != NULL)
go = FALSE;
}
lptr = &linerecord[0];
}
else
go = FALSE;
}
return j-1;
}
This falls apart when allocating new the third time (the third line of the keyword group). I assume I am doing something silly or corrupting the heap in some way but just cant see it and am now in zombie zone with this one. Is what I am passing through correct ? Any help at all would be appreciated..
Many Thx.