#include "stdio.h"
#include "string.h"
#include "math.h"
#include "stdlib.h"
#define N 10
struct bk
{
int no;
char cla[100];
char name[100];
char author[100];
char press[100];
int num;
float price;
float sumprice;
}books[N];
char str[80];
void read()
{
FILE *fp;
int i;
if((fp=fopen("D:\\CK0103.txt","r"))==NULL)
{
printf("can not open file");
exit(0);
}
fgets(str,80,fp);
for(i=0;i<N;i++)
fscanf(fp,"%d%s%s%s%s%d%f",&books[i].no,books[i].cla,books[i].name,books[i].author,books[i].press,&books[i].num,&books[i].price);
fclose(fp);
}
/*读数据文件*/
void display()
{
int i;
puts(str);
for(i=0;i<N;i++)
printf("%d%s%s%s%s%d%f\n",books[i].no,books[i].cla,books[i].name,books[i].author,books[i].press,books[i].num,books[i].price);
}
/*显示图书信息*/
void find_name()
{
char bn[50];
int i,flag=0; /*标记是否找到*/
printf("请输入要查询的书名:");
scanf("%s",bn);
for(i=0;i<N;i++)
if(strcmp(bn,books[i].name)==0)
{
printf("\n%-8d%-16s%-18s%-12s%-24s%-4d%-8.2f\n",books[i].no,books[i].cla,books[i].name,books[i].author,books[i].press,books[i].num,books[i].price);
flag=1;
}
if(i==N&&flag==0)
printf("sorry,没有找到!\n");
}
/*按书名查询*/