#ifndef _SIMPLE_BOOK_MANAGER_H
#define _SIMPLE_BOOK_MANAGER_H
typedef struct BookRecord
{
int index; //编号
char catalog[20]; //分类
char book_name[40]; //书名
char author[20]; //作者
char publisher[80]; //出版社
int quantity; //数量
float single_price; //单价
float total_price; //总价
}BookRecord, *PtrBookRecord;
typedef struct CatalogRecord
{
int index; //编号
char catalog[20]; //分类
int total_number; //总册数
}CatalogRecord, *PtrCatalogRecord;
#endif
void ReadBookRecord(BookRecord*, FILE*);
void FillRecord(char* line, BookRecord*);
FILE* open_file(const char* file_name);
void GetNumber(const char* file_name, char* number);
void print_main_menu();
char get_command();
void SearchAndDisplay(BookRecord*);
void Arrange(BookRecord*);
void PriceStat(BookRecord*, const char* output_file_name);
void NumberStat(BookRecord*, const char* output_file_name);
void print_search_and_disp_menu();
void SearchByName(BookRecord*);
void SearchByAuthor(BookRecord*);
void ShowAllBook(BookRecord*);
void print_head();
void print_book_record(BookRecord);
void print_arrange_menu();
void ArrangeByCatalog(BookRecord*);
void ArrangeByPublisher(BookRecord*);
int total_book_number;
int main(int argc, char* argv[])
{
FILE* fp;
char cmd;
char number[10] = {0};
char price_file_name[20] = {0};
char catalog_file_name[20] = {0};
BookRecord book_records[20];
int loop = 1;
memset(book_records, 0, sizeof(book_records));
if (argc >= 2)
{
fp = open_file(argv[1]);
GetNumber(argv[1], number);
}
else
{
char file_name[] = "DX0112.txt";
fp = open_file(file_name);
GetNumber(file_name, number);
}
if (fp == NULL)
{
printf("打开文件失败!");
return -1;
}
else
{
strcpy(price_file_name, "ZJ");
strcat(price_file_name, number);
strcat(price_file_name, ".txt");
strcpy(catalog_file_name, "ZL");
strcat(catalog_file_name, number);
strcat(catalog_file_name, ".txt");
}
ReadBookRecord(book_records, fp);
while (loop)
{
print_main_menu();
cmd = get_command();
switch(cmd)
{
case 'S': //查询显示
case 's':
SearchAndDisplay(book_records);
break;
case 'A': //排序
case 'a':
Arrange(book_records);
break;
case 'P': //统计总价
case 'p':
PriceStat(book_records, price_file_name);
break;
case 'N': //统计总册数
case 'n':
NumberStat(book_records, catalog_file_name);
break;
case 'Q':
case 'q':
loop = 0;
break;
default:
break;
}
}
fclose(fp);
}