我正在尝试编写一个程序,用于在我的计算机科学1课程中对速度约会信息进行排序以获得额外的学分;我遇到了一个奇怪的问题。程序在运行循环两次(在调用调试函数的位置)后,遇到一系列嵌套循环时崩溃。函数transferData;仅设计用于从文件中获取数据并将其移入结构中以供稍后处理,但尚未写入函数。我为我的生活无法弄清楚,所以任何建议都会非常受欢迎,下面我已经放置了代码,并在下面列出了我正在使用的测试数据。使用Structs调试C程序
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)。
要求陌生人通过检查发现代码中的错误并不富有成效。您应该使用调试器或打印语句来识别(或至少隔离)问题,然后回来一个更具体的问题(一旦您将其缩小到10行[测试案例](http:///sscce.org))。 –
您需要1.告诉我们哪条线路导致崩溃,2.告诉我们错误信息,以及3.将这些大量的代码烧录到一个代表性问题的小代表样本。 –
我很抱歉,为了防止混淆,我发布了整个代码;我将尝试重新格式化上述帖子。 – SigmusVictus