# include & ltstring.h & gt
# include & ltstdlib.h & gt
# Definition number 10
Structure library {
int num
char book _ name[30];
A character writer [30];
char sort _ num[3];
char pub _ company[30];
char pub _ time[30];
char price[30];
};
Typedef structure library LIB/* The definition of structure is used to store books and borrow books */
LIB LIB[N];
FILE * fpint all = 0;
Int menu (void);
Void input (void);
Void output (void);
Void save (void);
Void del (invalid);
Void search (void);
Void;
Master ()
{
for(; ; )
{
Switch (menu ()) {
Case1:input (); Break;
Case 2: output (); Break;
Case 3: save (); Break;
Case 4: Search (); Break;
Case 5: Modification (); Break;
Case 6: del (); Break;
Case 7: sort (); Break;
Case 0: Export (1); Break;
}/* Switch defines function output */
}
}
Int menu (invalid)
{
char m[3];
int n; Printf ("* * * * * * * * * * * * * * * * Welcome * * * * * * * * * * * * * * * * \ n \ n \ n");
Printf(" \ t \ t- book information management system-\ n ");
printf(" \ t \ t 1:input \ n ");
printf(" \ t \ T2:output \ n ");
printf(" \ t \ T3:save \ n ");
printf(" \ t \ T4:find \ n ");
printf(" \ t \ t5:modify \ n ");
printf(" \ t \ T6:delete \ n ");
printf(" \ t \ T7:statistics \ n ");
printf(" \ t \ t0:exit \ n ");
Printf ("\ t \ tPlease select an operation (0-6): \ n");
scanf("%s ",m);
n = atoi(m);
Return (n);
}/* Main interface */
Invalid input (invalid)
{
int I;
char m[3];
for(I = all; I & ltn;; i++)
{
all++;
Printf ("Please enter information: \ n");
Printf ("\ t \ tNo .. :\ n ");
scanf("%d ",& amplib[i]。 num);
printf(" \ t \ t title:\ n ");
scanf("%s ",lib[i].book _ name);
printf(" \ t \ t author:\ n ");
Scanf("%s ",lib[i]. Writer);
printf(" \ t \ t sort _ num:\ n ");
Scanf("%s ",lib[i]. sort _ number);
printf(" \ t \ tPublisher:\ n ");
scanf("%s ",lib[i].pub _ company);
Printf ("\ t \ tPublication date: \ n");
scanf("%s ",lib[i].pub _ time);
printf(" \ t \ t price:\ n ");
scanf("%s ",lib[i].prise);
A: printf("\t\tyes/ oh? \ n ");
printf(" \ t \ t 1:yes \ n ");
printf(" \ t \ T2:no \ n ");
scanf("%s ",m);
if(atoi(m)== 1)
Continue;
else if(atoi(m)==2)
Return;
other
{
Printf ("\ t \ tError! \ n ");
Go to a;
}/* Enter search criteria */
}
}
Invalid output (invalid)
{
int I;
for(I = 0; I < all; i++)
{
printf("\t\t%d\n ",lib[i]。 num);
printf("%s\t\t%s\t\t%s\n ",lib[i]。 book_name,lib[i]。 Writer, lib[i] Sort _ number);
printf("%s\t\t%s\t\t%s\n ",lib[i]。 pub_company,lib[i]。 pub_time,lib[i]。 prise);
}
}/* output the title, author, publication time, price, etc. */
Invalid save (invalid)
{
int I;
if((fp=fopen("file.c "," wb"))==NULL)
{
Printf ("Cannot open file");
Exit (1);
}
for(I = 0; I < all; i++)
{
if(fwrite(& amp; lib[i],sizeof(LIB), 1,fp)! = 1)
{
Printf ("Can't write!" );
Exit (1);
}
}/* Refuse to store if the conditions are not met */
fclose(FP);
}
Invalid search (void)
{
int i,flag
char m[3];
char name[30];
Printf ("\ t \ tPlease select your storage method: \ n");
Printf("\t\t 1: press the title! \ n ");
Printf("\t\t2: By author! \ n ");
scanf("%s ",m);
I = atoi(m);
Switch (1)
{
Case 1:{
Printf ("\ t \ tPlease enter a title: \ n");
Scanf("%s ",name);
flag = 0;
for(I = 0; I & ltn;; i++)
{
if(strcmp(name,lib[i].book_name)==0)
{
printf("\t\t%d\n ",lib[i]。 num);
printf("%s\t\t%s\t\t%s\n ",lib[i]。 book_name,lib[i]。 Writer, lib[i] Sort _ number);
printf("%s\t\t%s\t\t%s\n ",lib[i]。 pub_company,lib[i]。 pub_time,lib[i]。 prise);
flag = 1; Break;
}
}
If (flag ==0)
Printf ("\ t \ tThere is no such book! \ n ");
}
Case 2:{
Printf ("\ t \ tPlease enter the author: \ n");
Scanf("%s ",name);
flag = 0;
for(I = 0; I & ltn;; i++)
{
if(strcmp(name,lib[i].writer)==0)
{
printf("\t\t%d\n ",lib[i]。 num);
printf("%s\t\t%s\t\t%s\n ",lib[i]。 book_name,lib[i]。 Writer, lib[i] Sort _ number);
printf("%s\t\t%s\t\t%s\n ",lib[i]。 pub_company,lib[i]。 pub_time,lib[i]。 prise);
flag = 1; Break;
}
}
If (flag ==0)
Printf ("\ t \ tThere is no such author! \ n ");
}
}/* Find books by title or author and output */
}
Void (void)
{
int i,flag
char name[30],n[3];
Printf ("\ t \ tPlease enter a title to modify: \ n");
Scanf("%s ",name); /* Modify the title of the book */
flag = 0;
for(I = 0; I & ltn;; i++)
{
if(strcmp(name,lib[i].book_name)==0)
{
printf("\t\t%d\n ",lib[i]。 num);
printf("%s\t\t%s\t\t%s\n ",lib[i]。 book_name,lib[i]。 Writer, lib[i] Sort _ number);
printf("%s\t\t%s\t\t%s\n ",lib[i]。 pub_company,lib[i]。 pub_time,lib[i]。 prise);
Printf ("\ t \ tPlease enter the modified information: \ n");
printf(" \ t \ tnum:\ n ");
scanf("%d ",& amplib[i]。 num);
printf(" \ t \ t book _ name:\ n ");
scanf("%s ",lib[i].book _ name);
printf(" \ t \ t writer:\ n ");
Scanf("%s ",lib[i]. Writer);
printf(" \ t \ t sort _ num:\ n ");
Scanf("%s ",lib[i]. sort _ number);
printf(" \ t \ tpub _ company:\ n ");
scanf("%s ",lib[i].pub _ company);
printf(" \ t \ tpub _ time:\ n ");
scanf("%s ",lib[i].pub _ time);
printf(" \ t \ t price:\ n ");
scanf("%s ",lib[i].prise);
flag = 1; Break;
}
}/* Add books */
If (flag ==0)
Printf ("\ t \ tNot found! \ n ");
}
Void del (invalid)
{
int i,j,flag
char name[30];
Printf ("\ t \ tPlease enter a title to delete: \ n");
Scanf("%s ",name);
flag = 0;
for(I = 0; I & ltn;; i++)
{
if(strcmp(name,lib[i].book_name)==0)
{
printf("\t\t%d\n ",lib[i]。 num);
printf("%s\t\t%s\t\t%s\n ",lib[i]。 book_name,lib[i]。 Writer, lib[i] Sort _ number);
printf("%s\t\t%s\t\t%s\n ",lib[i]。 pub_company,lib[i]。 pub_time,lib[i]。 prise);
for(j = N; J> me; j -)
{
lib[j- 1]。 num=lib[j]。 num
strcpy(lib[j- 1])。 book_name,lib[j]。 book _ name);
strcpy(lib[j- 1])。 Author, lib[j]. Writer);
strcpy(lib[j- 1])。 sort_num,lib[j]。 Sort _ number);
strcpy(lib[j- 1])。 Publishing company, library [j]. pub _ company);
strcpy(lib[j- 1])。 pub_time,lib[j]。 pub _ time);
strcpy(lib[j- 1])。 prise,lib[j]。 prise);
flag = 1;
Printf ("\ t \ tIt has been deleted! \ n ");
Break;
}
}
}
If (flag ==0)
Printf ("\ t \ tThere is no such book! \ n ");
}/* Delete books */