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;
}
это основная часть нашей программы, которая должна получить один файл симуляции и неизвестное количество файлов станций и инициализировать из них структуру данных.
но когда мы пытаемся запустить проект, мы получаем ошибку «Debug Assertion Failed».
пожалуйста, если вы можете помочь нам решить проблему, которую мы должны представить в воскресенье.
спасибо!