I've gotten a crash in my program which seems fine to me, of course my program says otherwise, which confuses me.
This snippet of my function I am currently working on:
for(int k = 0; k < dictionary[k].size(); k++)
{
//"i" represents the fragment's first character
//while "k" represents the dictionary first character
if(fragments[i][j] == dictionary[k][j]) {
token++;
cout << token << endl;
}
}
might be the problem. When I debug the problem, the debugger goes to the first line in the snippet:
for(int k = 0; k < dictionary[k].size(); k++)
then crashes when I try go to the next. In the debugger, this window opens up in my Code Blocks:
Signal Received
Program Received Singal SIGEGV, segmentation fault. Do you want to view backtrace?
I clicked yes and it just seems arbitrary to me.
Does anyone know what I've done wrong?
If the backtrace is needed(the window says Call Stack), I'll edit it on later if needed
EDIT: This is the whole function, which I've thought it would not be necessary
void Language::compare()
{
int para = getParameters(0); //eg. 3
int valid = para;
int token = 0;
for(int i = 0; i < para; i++)
{
//If the string is creater than 2 characters
if(fragments[i].length() > 1) {
for(int j = 0; j < fragments[i].length(); j++)
{
//Checking if that character match in dictionary
for(int k = 0; k < para; k++) //Changed and now works,
{
//"i" represents the fragment's first character
//while "k" represents the dictionary first character
if(fragments[i][j] == dictionary[k][j]) { //But now this line crashes
token++;
cout << token << endl;
}
}
if(token == 0) {
break;
}
}
}
else {
//...
}
}
}
dictionary and fragments is declared in the class "Language" which are both vector.