我正在尝试编写一个程序,对我的计算机科学 1 课程中的速配信息进行分类以获得额外的学分;我遇到了一个奇怪的问题。程序在运行循环两次后遇到一系列嵌套循环时崩溃(在调用调试函数的地方)。函数传输数据;仅设计用于从文件中获取数据并将其移动到结构中,以便稍后由尚未编写的函数进行处理。我一生都想不通,所以非常欢迎任何建议,下面我已经放置了代码,下面是我正在使用的测试数据。
caData transferData(fData * fileData, caData * workingData, int numCouples)
{
int i = 0, j = 0, k = 0;
workingData->maData = (struct mData*)malloc(sizeof(mData)*(numCouples*2));//Create Array of Match Data with cells equal to double the number of couples
workingData->maData->couData = (struct cData*)malloc(sizeof(cData)*numCouples);//Create a Couple structure array with a number of cells equal to the number of couples.
///TODO:
//Read in Names
for(i = 0; i < (numCouples * 2); i++)//Rotate through Matches
{
if(i < numCouples)//Men First
{
debug();
for(j = 0; j < numCouples; j++)//Scan in First half of Couples
{
for(k = 0; k < numCouples; k++)//Scan In Male Names
{
fscanf(fileData->inputData, "%s", workingData->maData[i].couData[j].guyName);
}
for(k = 0; k < numCouples; k++)//Scan In Female Names
{
fscanf(fileData->inputData, "%s", workingData->maData[i].couData[j].girlName);
}
}
}
else//Now the women
{
for(j = 0; j < numCouples; j++)//Scan in First half of Couples
{
for(k = 0; k < numCouples; k++)//Scan In Female Names
{
fscanf(fileData->inputData, "%s", workingData->maData[i].couData[j].girlName);
}
for(k = 0; k < numCouples; k++)//Scan In male Names
{
fscanf(fileData->inputData, "%s", workingData->maData[i].couData[j].guyName);
}
}
}
}
//Read In Scores
//Compute differances
}
编辑:将代码压缩到错误的位置,即调用调试函数的位置;它运行两次,然后崩溃。它返回一个 -1073741819 (0xC0000005)。