贝茨方法:读取文件中的坐标

来源:百度文库 编辑:九乡新闻网 时间:2024/04/30 18:29:10
if(m_nBase!=0&&m_nTest!=0)
 {
      m_pBase=(struct Point *) malloc ((m_nBase+1)*sizeof(struct Point));
      m_pTest=(struct Point *) malloc ((m_nTest+1)*sizeof(struct Point));
     m_pBaseCost=(double *)malloc((m_nBase+1)*sizeof(double));
   char temp1[10];
   char temp2[10];
      for(i=0;i<(2*m_nBase+m_nTest);i++)
   {  
    fp.ReadString(str);
       if(i    {
          memset(temp1,'\0',10);
          memset(temp2,'\0',10);
       sscanf(str,"%s %s",temp1,temp2);
    m_pBase[i].x=atof(temp1);
    m_pBase[i].y=atof(temp2);
    }
    else if(i>=m_nBase&&i<(m_nBase+m_nTest))
    {
          memset(temp1,'\0',10);
          memset(temp2,'\0',10);
          sscanf(str,"%s %s",temp1,temp2);
    m_pTest[i-m_nBase].x=atof(temp1);
    m_pTest[i-m_nBase].y=atof(temp2);
    }
    else
    {
     j=i-m_nBase-m_nTest;
     memset(temp1,'\0',10);
     sscanf(str,"%s",temp1);
     m_pBaseCost[j]=atof(temp1);
    }
   }如果坐标之间为空格就用空格间隔,如果是,号就用,号间隔