int main(int argc, char* argv[])
{
FILE *pfd;//will get the file we are gone read from
char fileName[40];//get files name
char line[1024];
FILE *simulate;//will get the file we are gone read from
char line2[1024];
int arrSize=argc-2;
station * stations=( station * )malloc(sizeof(station)*(arrSize));//intilzing ther array
int i=2;//Auxiliary variable for the first for loop-reads information from all fiels
int j=0; //Auxiliary variable to help as clean the memory
ClientsLinkedList* data;
Link * temp;//temp varbale to help us clean the memory
Link * tempNext;
if(stations==NULL)
{
printf("Failed to allocate memory");
}
for(i;i<argc;i++)
{
data=CreateClientsLinkedList();
stations[i].m_clients=*data;
strcpy(fileName,argv[i]);
///* Open the file. If NULL is returned there was an error */
if((pfd = fopen("station.txt" , "r")) == NULL)
{
printf("Error Opening File.\n");
}
while( fgets(line, sizeof(line), pfd) != NULL )
{
ReadByCharName(line,stations,i);
}
fclose(pfd); /* Close the file */
}
////************************************************reading from simulation file*******************************************
/*** Open the file. If NULL is returned there was an error */
if((simulate = fopen("simulation.txt", "r")) == NULL)
{
printf("Error Opening File.\n");
}
while( fgets(line, sizeof(line2), simulate) != NULL )
{
ReadSimulation( line2,arrSize,stations);
}
fclose(simulate); /* Close the file */
////*********************************************clening memory****************************************
for(j;j<arrSize;j++)
{
temp=stations[j].m_clients.m_head;
while(temp!=NULL)
{
tempNext=temp->m_next;
free(temp);
temp=tempNext;
}
}
free(stations);
return 0;
}
这是我们程序的主要内容,该过程将获取一个模拟文件并未知数量的工作站文件,并初始化其中的数据结构。
但是,当我们尝试运行项目时,会收到“调试断言失败”错误。
如果您可以帮助我们解决问题,请在星期日之前提交项目。
谢谢!
最佳答案
这里至少有一个错误:stations[i].m_clients=*data;
:我相信我从2开始。