这是工程的一部分。分类统计功能,可以运行,但输入后就会停止没结果
#include "facility.h"void Tongji(ADDR *top)
{
ADDR *p;
int sel;
int flag2=0;int ha=0;
char find[20];
p=top->next;
if(!top->next)
{
printf("\n>>>>>>>>>>提示:没有资料可以统计分类!\n");
return;
}
printf(">>>>>>>>>>提示:\n=====>0退出\n=====>1按设备号统计\n=====>2按设备名称统计\n");
scanf("%d",&sel);
if(sel==1)
{
printf("\n输入你要统计分类的设备号:");
scanf("%s",find);
while(p)
{
if(strcmp(p->number,find)==0)
{flag2++;}
if(flag2==1&&ha!=flag2)
{
printf("\n%s%s%s%f%s%s%s\n",p->number,p->name,p->kind,p->price,p->year,p->manufactory,p->scrap,p->scrapyear);
ha=flag2;
}
else
if(flag2>ha)
{printf("\n%-13s%-11s%-7s%-10s%-13s%-10s%-5s\n",p->number,p->name,p->kind,p->price,p->year,p->manufactory,p->scrap,p->scrapyear);
ha=flag2;
}
p=p->next;
}
if(flag2)
{
printf("\n*************************按设备号%s统计分类的有%d条记录:*************************\n\n",find,flag2);
}
else
{printf("\n按设备号%s统计的结果为0个\n\n",find);}
}
else if(sel==2)
{
printf("\n输入你要统计分类的设备名称:");
scanf("%s",find);
while(p)
{
if(strcmp(p->name,find)==0)
{flag2++;}
if(flag2==1&&ha!=flag2)
{ printf("\n%-13s%-11s%-7s%-10s%-13s%-10s%-5s\n",p->number,p->name,p->kind,p->price,p->year,p->manufactory,p->scrap,p->scrapyear);
ha=flag2;
}
else
if(flag2>ha)
{printf("\n%-13s%-11s%-7s%-10s%-13s%-10s%-5s\n",p->number,p->name,p->kind,p->price,p->year,p->manufactory,p->scrap,p->scrapyear);
ha=flag2;
}
p=p->next;
}
if(flag2)
{
printf( "\n******************按设备名称%s统计的有%d条记录:********************\n\n",find,flag2);
}
else {printf("\n按设备名称%s统计分类的结果为0个\n\n",find);}
}
else if(sel==0) return;
}