My excersize program used to extract English words from a library

来源:互联网 发布:中关村网盘数据 编辑:程序博客网 时间:2024/05/16 09:57

void CReadDictionaryDlg::OnRead()
{
 // TODO: Add your control notification handler code here 
 char chRead[1] = {0};
 CFile flRead;]
 // BOOL bOpen = flRead.Open("CK-N4.PMS",CFile::modeRead|CFile::typeBinary); 
 BOOL bOpen = flRead.Open("CK-TL.PMS",CFile::modeRead|CFile::typeBinary); 
 //There are three colum for a English word:Word alphabet, Phenonen, Chinese Notation
 BOOL bFirstWord = FALSE, bSecondWord = FALSE, bThirdWord = FALSE;
 //Encount a space first time
 BOOL bFirstEncounterSpace = FALSE;
 
 std::string strWord[3];
 int iWordEncounter = 0;
 int nGroup25 = 0;
 if(bOpen)
 {
  flRead.Seek(0xbc1,CFile::begin);
  const int nLength = flRead.GetLength() - 0xbc2 -0x67B;
  int nPos = 0;
  flRead.Read((void*)chRead,1);
  bFirstWord = !bFirstWord;
  while( nPos != nLength)
  {
   flRead.Read((void*)chRead,1);
   if(chRead[0] == 0x20)
   {
    if(!bFirstEncounterSpace)
    {
     bFirstEncounterSpace = TRUE;
     iWordEncounter ++;
     nGroup25 ++;
     if(iWordEncounter%3 != 2)
     {
      char chTemp[80];
      strcpy(chTemp,strWord[iWordEncounter-1].c_str());
      m_strDisplayWord += strWord[iWordEncounter-1].c_str();
      m_strDisplayWord += "/r/n";
     }    
    }
   }
   else
   {
    if(bFirstEncounterSpace)
    {
     if(!(nGroup25%75))
     {
      static int nTemp = 1;
      nTemp ++;
      bFirstEncounterSpace = FALSE;
      
      flRead.Seek(79, CFile::current);
      nPos += 80;
      
      strWord[iWordEncounter] = "";
     }
     else
     {
      bFirstEncounterSpace = FALSE;
      iWordEncounter = (iWordEncounter)%3;
      strWord[iWordEncounter] = "";
      strWord[iWordEncounter] += chRead[0];
     }     
    }
    else
    {
     strWord[iWordEncounter] += chRead[0];
    }

   }

   nPos ++;
  }
  
  flRead.Close();
 } 

 UpdateData(FALSE);
}