设置标志位提取字符串

来源:互联网 发布:360°全景图js 编辑:程序博客网 时间:2024/05/29 04:15

写入文件时确保没有和标志字符相同的地方,

//写入文件时

 FILE * pfwrite = NULL;

 pfwrite = fopen("C://Documents and Settings//zrc//桌面//test//报警写文件读文件设置标志//test.txt","a+");

 if (pfwrite != NULL) {
  CString strAlarm;

  SYSTEMTIME   SysTime;  
  CString   StrCurTime;  
  ::GetLocalTime(&SysTime);  
  StrCurTime.Format("%d.%d.%d_%d:%d:%d",SysTime.wYear,SysTime.wMonth,SysTime.wDay,SysTime.wHour,SysTime.wMinute,SysTime.wSecond);
  
  int i = 555;
  strAlarm.Format("%d",i);
 
  fprintf(pfwrite,StrCurTime + " time ");
  fprintf(pfwrite,strAlarm + " number ");
  fclose(pfwrite);
 }
 

 

//读取文件时

 FILE * pfread = NULL;
 pfread = fopen("C://Documents and Settings//zrc//桌面//test//报警写文件读文件设置标志//test.txt","r");

 char temp[1000];
 char temp1[1000];
 if (pfread != NULL) {
  fscanf(pfread, "%s",temp);
  MessageBox(temp);
  fscanf(pfread, "%s",temp1);

  //提取时间
  while (feof(pfread) == 0) {
   while (1) {
    if (!strcmp(temp1,"time")) {//这里的TEMP是真正提取的东西
     //MessageBox(temp);
     break;
    }
    else
    {
     //如果不是time,就将此次提取的字符串,和上次的字符串相加起来
     strcat(temp,temp1);
     memset(temp1,0,sizeof(temp1));
     fscanf(pfread, "%s",temp1);
    }
   }
   
   fscanf(pfread, "%s",temp);
   fscanf(pfread, "%s",temp1);
   

   //提取报警宏
  
   while (1) {
    if (!strcmp(temp1,"number")) {//这时的TEMP是真正提取的东西
     //MessageBox(temp);
     break;
    }
    else
    {
     //如果不是time,就将此次提取的字符串,和上次的字符串相加起来
     strcat(temp,temp1);
     memset(temp1,0,sizeof(temp1));
     fscanf(pfread, "%s",temp1);
    }
   }
   fscanf(pfread, "%s",temp);
   fscanf(pfread, "%s",temp1);
  }
 
  
 }

原创粉丝点击