【发布时间】:2009-09-03 21:21:31
【问题描述】:
我的程序崩溃了,这对我来说似乎很好,当然我的程序不是这样,这让我感到困惑。
我目前正在处理的函数的这个 sn-p:
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;
}
}
可能是问题所在。当我调试问题时,调试器会转到 sn -p 中的第一行:
for(int k = 0; k < dictionary[k].size(); k++)
然后当我尝试进入下一个时崩溃。 在调试器中,这个窗口在我的代码块中打开:
Signal Received
Program Received Singal SIGEGV, segmentation fault. Do you want to view backtrace?
我点击了“是”,这对我来说似乎是任意的。
有谁知道我做错了什么?
如果需要回溯(窗口显示调用堆栈),如果需要,我稍后会对其进行编辑
编辑:这是整个功能,我认为没有必要
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 {
//...
}
}
}
字典和片段在“语言”类中声明,它们都是向量。
【问题讨论】:
-
我认为我们需要多看一点。片段和字典是如何声明和初始化的?崩溃时 i、j 和 k 的值是多少?