📄 arithmetic.cpp
字号:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<iostream.h>
#include <malloc.h>
#include"define.h"
EachAlert * Get_Alert(sensor* L,int number)
{
FILE *PFile=OpenFile(L);
int count=0;
int i=0,j=0,l=0;//src[],dst[],time[]的第几位
int k=0;//一行中第几位数
char word;
EachAlert *Current;
InitList(Current);
char src[9];
char dst[9];
char time[3];
for (int i0=0;i0<9;i0++)
{
src[i0]=NULL;
dst[i0]=NULL;
}
for (int i1=0;i1<3;i1++)
{
time[i1]=NULL;
}
while((word=fgetc(PFile))!=EOF&&count<number)
{
if(k<8)
{
src[i]=word;
i++;
k++;
}
else
if(k>8&&k<17)
{
src[i]='\0';
dst[j]=word;
j++;
k++;
}
else
if(k>17&&k<20)
{
if (word!='\n')
{
dst[j]='\0';
time[l]=word;
l++;
k++;
}
else//判断时间是一位还是两位
{
time[l]='\0';
i=0;j=0;k=0;l=0;
count++;
if (count==number)
{
for (int i1=0;i1<9;i1++)
{
Current->src[i1]=src[i1];
Current->dst[i1]=dst[i1];
}
for (int j1=0;j1<3;j1++)
{
Current->time[j1]=time[j1];
}
}
}
}
else
if(k==8||k==17)
{
k++;
}
else
{
time[l]='\0';
i=0;j=0;k=0;l=0;
count++;
if (count==number)
{
for (int i1=0;i1<9;i1++)
{
Current->src[i1]=src[i1];
Current->dst[i1]=dst[i1];
}
for (int j1=0;j1<3;j1++)
{
Current->time[j1]=time[j1];
}
}
}
}
fclose(PFile);
return Current;
}
EachAlert* Scan_Alert(EachAlert *EL,sensor *SL)
{
sensor *Current_Sensor,*First_Sensor;
Current_Sensor=First_Sensor=SL;
EachAlert *Current_EachAlert,*New_EachAlert,*First_EachAlert;
InitList(New_EachAlert);
First_EachAlert=New_EachAlert;
Current_EachAlert=EL;
FILE *Pfile;
if(Current_EachAlert!=NULL)
{
while(Current_Sensor->next!=Current_Sensor&&Current_Sensor->rec[0]!=NULL)//增加后面条件为了使当Current_Sensor只有一位时,判断仅有的一位内容是否为空
{
Pfile=OpenFile(Current_Sensor);//打开record数据类型current对应的文件
Current_Sensor=Current_Sensor->next;
//AlertRecord *Current_AlertRecord,*Temp_AlertRecord,*First_AlertRecord;
int i=0,j=0,l=0;//src[],dst[],time[]的第几位
int k=0;//一行中第几位数
char word;
char src[9];
char dst[9];
char time[3];
for (int i0=0;i0<9;i0++)
{
src[i0]=NULL;
dst[i0]=NULL;
}
for (int i1=0;i1<3;i1++)
{
time[i1]=NULL;
}
while((word=fgetc(Pfile))!=EOF)
{
if(k<8)
{
src[i]=word;
i++;
k++;
}
else
if(k>8&&k<17)
{
src[i]='\0';
dst[j]=word;
j++;
k++;
}
else
if(k>17&&k<20)
{
if (word!='\n')
{
dst[j]='\0';
time[l]=word;
l++;
k++;
}
else//判断时间是一位还是两位
{
time[l]='\0';
i=0;j=0;k=0;l=0;
if (strlen(Current_EachAlert->time)==strlen(time)&&strcmp(time,Current_EachAlert->time)>0)
{
break;
}
else
{
if((strcmp(dst,Current_EachAlert->src)==0&&(strcmp(time,Current_EachAlert->time)<=0&&strlen(Current_EachAlert->time)==strlen(time)))
||(strcmp(dst,Current_EachAlert->src)==0&&strlen(Current_EachAlert->time)>strlen(time)))//由于时间有1为和2为的区别,单纯用strcmp很难进去完全的比较大小,所以要添加strlen区分其长度
{
strcpy( New_EachAlert->src,src);
strcpy(New_EachAlert->dst,dst);
strcpy(New_EachAlert->time,time);
New_EachAlert->count=New_EachAlert->count+1;
WriteToTxt(New_EachAlert);
InitList(New_EachAlert->next);
New_EachAlert=New_EachAlert->next;
}
}
}
}
else
if(k==8||k==17)
{
k++;
}
else
{
time[l]='\0';
i=0;j=0;k=0;l=0;
if (strlen(Current_EachAlert->time)==strlen(time)&&strcmp(time,Current_EachAlert->time)>0)
{
break;
}
else
{
if((strcmp(dst,Current_EachAlert->src)==0&&(strcmp(time,Current_EachAlert->time)<=0&&strlen(Current_EachAlert->time)==strlen(time)))
||(strcmp(dst,Current_EachAlert->src)==0&&strlen(Current_EachAlert->time)>strlen(time)))//由于时间有1为和2为的区别,单纯用strcmp很难进去完全的比较大小,所以要添加strlen区分其长度
{
strcpy( New_EachAlert->src,src);
strcpy(New_EachAlert->dst,dst);
strcpy(New_EachAlert->time,time);
New_EachAlert->count=New_EachAlert->count+1;
WriteToTxt(New_EachAlert);
InitList(New_EachAlert->next);
New_EachAlert=New_EachAlert->next;
}
}
}
}
fclose(Pfile);
New_EachAlert->next=NULL;
}
//Current_Sensor=First_Sensor;
}
return First_EachAlert;
}
void FindElem(sensor *L,EachAlert *EL,bool choice)
{
sensor * current;
FILE *Pfile;
current=L;
// AlertRecord *First_Alert,*Current_Alert,*Temp_Alert;
int x=0;
if (true==choice)
{
while(current->next!=current&¤t->rec[0]!=NULL)
{
Pfile=OpenFile(current);
int i=0,j=0,l=0;//src[],dst[],time[]的第几位
int k=0;//一行中第几位数
char word;
char src[9];
char dst[9];
char time[3];
for (int i0=0;i0<9;i0++)
{
src[i0]=NULL;
dst[i0]=NULL;
}
for (int i1=0;i1<3;i1++)
{
time[i1]=NULL;
}
while((word=fgetc(Pfile))!=EOF)//&&strcmp(Prior_AlertRecord->time,Current_EachAlert->time)<=0)
{
if(k<8)
{
src[i]=word;
i++;
k++;
}
else
if(k>8&&k<17)
{
src[i]='\0';
dst[j]=word;
j++;
k++;
}
else
if(k>17&&k<20)
{
if (word!='\n')
{
dst[j]='\0';
time[l]=word;
l++;
k++;
}
else//判断时间是一位还是两位
{
time[l]='\0';
i=0;j=0;k=0;l=0;
if (strcmp(dst,EL->dst)==0)
{
if (x>0)
{
break;
}
else
{
current->w=current->w+1;
x++;
// WriteToOther(current);
}
}
}
}
else
if(k==8||k==17)
{
k++;
}
else
{
time[l]='\0';
i=0;j=0;k=0;l=0;
if (strcmp(dst,EL->dst)==0)
{
if (x>0)
{
break;
}
else
{
current->w=current->w+1;
x++;
// WriteToOther(current);
}
}
}
}
fclose(Pfile);
current=current->next;
x=0;
}
}
else
{
while(current->next!=current&¤t->rec[0]!=NULL)
{
Pfile=OpenFile(current);
int i=0,j=0,l=0;//src[],dst[],time[]的第几位
int k=0;//一行中第几位数
char word;
char src[9];
char dst[9];
char time[3];
for (int i0=0;i0<9;i0++)
{
src[i0]=NULL;
dst[i0]=NULL;
}
for (int i1=0;i1<3;i1++)
{
time[i1]=NULL;
}
while((word=fgetc(Pfile))!=EOF)//&&strcmp(Prior_AlertRecord->time,Current_EachAlert->time)<=0)
{
if(k<8)
{
src[i]=word;
i++;
k++;
}
else
if(k>8&&k<17)
{
src[i]='\0';
dst[j]=word;
j++;
k++;
}
else
if(k>17&&k<20)
{
if (word!='\n')
{
dst[j]='\0';
time[l]=word;
l++;
k++;
}
else//判断时间是一位还是两位
{
time[l]='\0';
i=0;j=0;k=0;l=0;
if (strcmp(dst,EL->src)==0)
{
if (x>0)
{
break;
}
else
{
current->w=current->w+1;
x++;
// WriteToOther(current);
}
}
}
}
else
if(k==8||k==17)
{
k++;
}
else
{
time[l]='\0';
i=0;j=0;k=0;l=0;
if (strcmp(dst,EL->src)==0)
{
if (x>0)
{
break;
}
else
{
current->w=current->w+1;
x++;
// WriteToOther(current);
}
}
}
}
fclose(Pfile);
current=current->next;
x=0;
}
}
}
bool FindElem(sensor *L,EachAlert *EL)
{
sensor * current;
current=L;
FILE *Pfile;
bool choice=false;
while(current->next!=current&¤t->rec[0]!=NULL)
{
Pfile=OpenFile(current);
int i=0,j=0,l=0;//src[],dst[],time[]的第几位
int k=0;//一行中第几位数
char word;
char src[9];
char dst[9];
char time[3];
for (int i0=0;i0<9;i0++)
{
src[i0]=NULL;
dst[i0]=NULL;
}
for (int i1=0;i1<3;i1++)
{
time[i1]=NULL;
}
while((word=fgetc(Pfile))!=EOF)//&&strcmp(Prior_AlertRecord->time,Current_EachAlert->time)<=0)
{
if(k<8)
{
src[i]=word;
i++;
k++;
}
else
if(k>8&&k<17)
{
src[i]='\0';
dst[j]=word;
j++;
k++;
}
else
if(k>17&&k<20)
{
if (word!='\n')
{
dst[j]='\0';
time[l]=word;
l++;
k++;
}
else//判断时间是一位还是两位
{
time[l]='\0';
i=0;j=0;k=0;l=0;
if (strcmp(dst,EL->src)==0)
{
choice=true;
break;
}
}
}
else
if(k==8||k==17)
{
k++;
}
else
{
time[l]='\0';
i=0;j=0;k=0;l=0;
if (strcmp(dst,EL->src)==0)
{
choice=true;
break;
}
}
}
fclose(Pfile);
if(true==choice)
break;
else
current=current->next;
}
return choice;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -