原创 VC 从文本中读取数据

2008-9-2 13:26 3105 7 7 分类: 软件与OS

 CStdioFile fp;
 CString strFileName,cmdRecord;
 byte cmd,addr,data0,data1,data2,data3;


 CFileDialog MyDialog(true,"","",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Text Files (*.txt)|*.txt|"); // open file menu (construct CFileDialog object)
 


 if (MyDialog.DoModal()==IDOK)
 {
  strFileName = MyDialog.GetPathName();
  if(!fp.Open(strFileName,CFile::modeRead |CFile::typeText))
  {
   MessageBox("Cannot open command file","Multi-Ucodes",MB_ICONERROR|MB_OK); // file cannot be opened (not existing)
   return;
  }
  else
  {
   USHORT numRecord="0";
   while(fp.ReadString(cmdRecord))
   {
    if (cmdRecord.Left(1) != '#')
    {
     sscanf(cmdRecord,"%x%x%x%x%x",&addr,&cmd,&data1,&data2,&data3);
     numRecord++;
     if (numRecord >= 100)
     {
      MessageBox("Warning: command list is too large,only 100 cmd can be executed!", "Multi-Ucode", MB_ICONWARNING|MB_OK);
      break;
     }
    }
   }
   fp.Close();
  }
 }
  

文章评论0条评论)

登录后参与讨论
我要评论
0
7
关闭 站长推荐上一条 /2 下一条