【问题标题】:Debug Assertion Failed in Visual Studio cVisual Studio c 中的调试断言失败
【发布时间】:2010-11-12 19:08:34
【问题描述】:
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”错误。 如果您能帮助我们解决我们需要在周日提交项目的问题。

谢谢!

【问题讨论】:

  • 请停止编写代码。如果您在一个简单的家庭作业问题上寻求帮助,而您的入门课程使用的是 C,那么您注定会失败。
  • @Conrad:我的介绍课使用了 C。这很棒。在我的学校,工程专业必须学习 C。CS 是唯一使用 java 的。

标签: c debugging


【解决方案1】:

这里至少有一个错误:stations[i].m_clients=*data;:我相信我从 2 开始。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2014-09-09
    • 2016-04-21
    相关资源
    最近更新 更多