目的是通过文件查找
可是我在输入的时候输一次就跳回了
怎么才能把3个要输入的一次都输入
#include <stdio.h>
#define SIZE 3
struct date
{
int year;
int month;
int day;
};
struct book
{
char name[15];
char author[15];
char puthor[15];
struct date time;
float price;
int ln;
int fn;
}book[SIZE];
void save()
{
FILE *fp;
int i;
if((fp=fopen("bk_list","w"))==NULL)
{
printf("cannot open file \n");
return;
}
for(i=0;i<3;i++)
if(fwrite(&book[i],sizeof(struct book),1,fp)!=1)
printf("file write error \n");
fclose(fp);
}
void scan()
{
int i;
printf("Input the information:\n");
printf("name author puthor year month day price ln fn \n");
for(i=0;i<SIZE;i++)
scanf("%s%s%s%d%d%d%f%d%d",book[i].name,book[i].author,book[i].puthor,&book[i].time.year,&book[i].time.month,&book[i].time.day,&book[i].price,&book[i].ln,&book[i].fn);
save();
}
void load()
{
FILE *fp;
int i;
fp=fopen("bk_list","r");
printf("name author puthor year month day price ln fn\n");
for(i=0;i<SIZE;i++)
{ fread(&book[i],sizeof(struct book),1,fp);
printf("%-10s %-15s %-15s %4d %2d %2d %f %5d %5d \n",book[i].name,book[i].author,book[i].puthor,book[i].time.year,book[i].time.month,book[i].time.day,book[i].price,book[i].ln,book[i].fn);
}
fclose(fp);
}
search1()
{
char a[10];
int i;
FILE *fp;
printf("please input book-name\n");
if((fp=fopen("bk_list","rb"))==NULL)
{
printf("cannot open infile\n");
return;
}
scanf("%s",a);
for(i=0;i<SIZE;i++)
{
fread(&book[i],sizeof(struct book),1,fp);
if(strcmp(a,book[i].name)==0)
printf("%-10s %-15s %-15s %4d %2d %2d %f %5d %5d \n",book[i].name,book[i].author,book[i].puthor,book[i].time.year,book[i].time.month,book[i].time.day,book[i].price,book[i].ln,book[i].fn);
}
fclose(fp);
}
search2()
{
char a[10];
int i;
FILE *fp;
printf("please input author-name\n");
if((fp=fopen("bk_list","rb"))==NULL)
{
printf("cannot open infile\n");
return;
}
scanf("%s",a);
for(i=0;i<SIZE;i++)
{
fread(&book[i],sizeof(struct book),1,fp);
if(strcmp(a,book[i].name)==0)
printf("%-10s %-15s %-15s %4d %2d %2d %f %5d %5d \n",book[i].name,book[i].author,book[i].puthor,book[i].time.year,book[i].time.month,book[i].time.day,book[i].price,book[i].ln,book[i].fn);
}
fclose(fp);
}
main()
{
int c;
printf("This is the book system.\n");
printf("Input 1,you can import all the information of the books.\n");
printf("Input 2,you can see all the information of the books.\n");
printf("Input 3,you can import the credit to look up the information of the books.\n");
printf("Input 4,you can import the quality to look up the information of the books.\n");
scanf("%d",&c);
switch(c)
{
case 1:scan();break;
case 2:load();break;
case 3:search1();break;
case 4:search2();break;
default:printf("error");
}
}