#include <stdio.h>
void putup()
{
struct key
{
int shaftdia[2];
int keywidth;
int keyheigh;
float shaftT;
float wheelhub;
}
shaftdim[10];
FILE *fp;
int i,j;
for(i=0;i<10;i++)
{
for(j=0;j<2;j++)
{
printf("\n输入轴径:\n");
scanf("%d",&shaftdim[i].shaftdia[j]);
}
printf("键宽:");
scanf("%d",&shaftdim[i].keywidth);
printf("键高:");
scanf("%d",&shaftdim[i].keyheigh);
printf("轴:");
scanf("%f",&shaftdim[i].shaftT);
printf("轮毂:");
scanf("%f",&shaftdim[i].wheelhub);
}
fp=fopen("keydim","w");
for(i=0;i<10;i++)
{
if(fwrite(&shaftdim[i],sizeof(struct key),1,fp)!=1)
printf("文件出错/n");
}
fclose(fp);
fp=fopen("keydim","r");
for(i=0;i<10;i++)
{
fread(&shaftdim[i],sizeof(struct key),1,fp);
float upprintf("%d,%d,%d,%d,%f,%f\n",shaftdim[i].shaftdia[0],shaftdim[i].shaftdia[1],shaftdim[i].keywidth,shaftdim[i].keyheigh,shaftdim[i].shaftT,shaftdim[i].wheelhub);
}
}
void find()
{
struct key
{
int shaftdia[2];
int keywidth;
int keyheigh;
float shaftT;
float wheelhub;
}
shaftdim[10];
FILE *fp;
int shaftdia,i;
printf("\n 请输入轴径d:\n");
scanf("%d",&shaftdia);
fp=fopen("keydim","r");
for(i=0;i<10;i++)
{
fread(&shaftdim[i],sizeof(struct key),1,fp);
if(shaftdia<shaftdim[i].shaftdia[1])
{
printf("%d,%d,%d,%d,%f,%f\n",shaftdim[i].shaftdia[0],shaftdim[i].shaftdia[1],shaftdim[i].keywidth,shaftdim[i].keyheigh,
shaftdim[i].shaftT,shaftdim[i].wheelhub);
break;
}
}
fclose(fp);
}
void jiemian()
{
printf("\n请选择:1 录入数据 2 查数据 0 退出\n");
int a;
scanf("%d",&a);
switch(a)
{
case 1:
putup();
break;
case 2:
find();
break;
case 0:
break;
default:printf("\n输入有误!:");
jiemian();
}
}
void main()
{
jiemian();
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论