学了一个多学期的c语言,还是有必要去记录一下自己的学习进程的,做一次课设会让自己发现很多不足的地方,也加深了对编程和程序的理解,下面是一些我自己做的一个c语言程序,关于藏书管理信息系统的一个程序,我将功能相似的部分用文件的形式分割开来。
在使用这样写的程序时,需要先创建一个工程项目,然后将这些文件添加到项目中去,才能正常运行,否者系统不会自己识别是不是一个程序的,会报错
主函数
#include <stdio.h> #include <process.h> #include "Book.h" #include "File.h"
void showMainMenu(); void run(); void showbookZRMenu(); void printHZHeader(); void printBookHZ(); void printAllBook(); void enterbookZR(); void showbookRKMenu(); void RKBook(); void enterbookRK(); void showbookCXMenu(); void enterbookCX(); void showbookXGMenu(); void modifBook(); void deletBook(); void enterbookXG(); void showhelpMenu(); void printhHeple(); void printXTxinxi(); void enterhelp(); void CSH(); void start(); void end();
BookTable bookTable;//全局变量? //藏书管理信息系统 //子系统:作者编写的书 ? //页面设计 ?//主页面? ? char mainMenu[] = "----------------------------------------------------------\n"
" ? ? ? ? ? ? ? ? ? 欢迎使用藏书管理信息系统\n"? "----------------------------------------------------------\n" "?? ??? ??? ?1、图书总览\n" "----------------------------------------------------------\n"? "?? ??? ??? ?2、图书入库\n" "----------------------------------------------------------\n" "?? ??? ??? ?3、图书查询\n" "----------------------------------------------------------\n" "?? ??? ??? ?4、修改信息\n" "----------------------------------------------------------\n" "?? ??? ??? ?5、帮 ? ?助\n" "----------------------------------------------------------\n" "?? ??? ??? ?6、退出软件\n"? "----------------------------------------------------------\n" "请选择:"; //1、图书总览? char bookZRMenu[] = "-------------------------------------------------------- --\n" " ? ? ? ? ? ? ? ?藏书管理系统---图书总览\n"? "----------------------------------------------------------\n" "?? ??? ?请选择查看的方式\n" "----------------------------------------------------------\n" "?? ??? ?1、查看图书汇总的信息\n" "----------------------------------------------------------\n" " ? ? ?? ??? ?2、查看全部图书的详细信息\n" "----------------------------------------------------------\n" "?? ??? ?3、返回(按任意键继续)\n"? "----------------------------------------------------------\n" ;
//2、图书入库 char bookRKMenu[] = "----------------------------------------------------------\n" " ? ? ? ? ? ? ? ?藏书管理系统---图书入库\n"? "----------------------------------------------------------\n" "?? ??? ?1、录入图书信息\n" "----------------------------------------------------------\n" "?? ??? ?2、返回(按任意键继续)\n"? "----------------------------------------------------------\n" ; //3、图书查询 char bookCXMenu[] ="----------------------------------------------------------\n" " ? ? ? ? ? ? ? ?藏书管理系统---图书查询\n"? "----------------------------------------------------------\n" "?? ??? ?1、按作者姓名查找\n" "----------------------------------------------------------\n" "?? ??? ?2、按图书名称查找\n" "----------------------------------------------------------\n"? "?? ??? ?3、返回(按任意键继续)\n"? "----------------------------------------------------------\n" ;
//4、修改信息 char bookXGMenu[] ="----------------------------------------------------------\n" " ? ? ? ? ? ? ? ?藏书管理系统---修改信息\n"? "----------------------------------------------------------\n" "?? ??? ?1、修改图书信息\n" "----------------------------------------------------------\n" "?? ??? ?2、删除图书信息\n" "----------------------------------------------------------\n"? "?? ??? ?3、返回(按任意键继续)\n"? "----------------------------------------------------------\n" ; //5、帮 ? ?助 char helpMenu[] ="----------------------------------------------------------\n" " ? ? ? ? ? ? ? ?藏书管理系统---帮助\n"? "----------------------------------------------------------\n" "?? ??? ?1、查看帮助\n" "----------------------------------------------------------\n" "?? ??? ?2、查看系统信息\n" "----------------------------------------------------------\n" "?? ??? ?3、返回(按任意键继续)\n"? "----------------------------------------------------------\n"? ; //6、退出软件 char TUCHUMenu[] ="----------------------------------------------------------\n" " ? ? ? ? ? ? ?欢迎下次使用藏书管理系统\n"? "----------------------------------------------------------\n" ;
//主页面的开始? void showMainMenu() { ?? ?system("cls"); // 调用DOD命令cls清屏 ?? ?printf("%s", mainMenu); } void run()? { ?? ?char cmd; ?? ?while (1)? ?? ?{ ?? ??? ?showMainMenu(); // 显示菜单 ?? ??? ? ?? ??? ?cmd = getchar(); ?? ??? ?getchar(); // 清除输入流中留下的'\n' ?? ??? ?switch (cmd)? ?? ??? ?{ ?? ??? ?case '1': ?? ??? ??? ?enterbookZR();? ?? ??? ??? ?break; ?? ??? ?case '2': ?? ??? ??? ?enterbookRK(); ?? ??? ??? ?break; ?? ??? ?case '3': ?? ??? ??? ?enterbookCX(); ?? ??? ??? ?break; ?? ??? ?case '4': ?? ??? ??? ?enterbookXG(); ?? ??? ??? ?break; ?? ??? ?case '5': ?? ??? ??? ?enterhelp(); ?? ??? ??? ?break;?? ? ?? ??? ?case '6': ?? ??? ??? ?printf("退出了系统\n"); ?? ??? ??? ?return; ?? ??? ?default: ?? ??? ??? ?printf("错误命令!\n");?? ??? ??? ??? ??? ? ?? ??? ?} ?? ?} } //1、图书总览 void showbookZRMenu() { ?? ?system("cls"); // 调用DOD命令cls清屏 ?? ?printf("%s", bookZRMenu); } void printHZHeader() { ?? ?printf("%-12s", "总的作者"); ?? ?printf("%-12s", "总的图书"); ?? ?printf("%-12s", "在库数量\n"); } void printBookHZ() { ?? ?int author=bookTable.counts; ?? ?int name=bookTable.counts; ?? ?int Allnumber=0; ?? ?int i=0; ?? ?for(i;i<name;i++) ?? ?{ ?? ??? ?Allnumber += bookTable.bookArray[i].number; ?? ?} ?? ?printf("%-12d",bookTable.counts); ?? ?printf("%-12d",name); ?? ?printf("%-12d\n",Allnumber); } void printAllBook() { ?? ?int j=bookTable.counts; ?? ?int i=0; ?? ?for(i;i<j;i++) ?? ?{ ?? ??? ?printBook(&bookTable.bookArray[i]); ?? ??? ? ?? ?} } void enterbookZR() { ?? ?char cmd; ?? ?while (1) { ?? ??? ?showbookZRMenu(); ?? ??? ?cmd = getchar(); ?? ??? ?getchar(); ?? ??? ?switch (cmd) { ?? ??? ?case '1':?? ??? ??? ?//查看全部图书的汇总信息? ?? ??? ??? ?printHZHeader();? ?? ??? ??? ?printBookHZ(); ?? ??? ??? ?break; ?? ??? ?case '2':?? ??? ??? ?//查看全部图书信息? ?? ??? ??? ?printHeader(); ?? ??? ??? ?printAllBook(); ?? ??? ??? ?break; ?? ??? ?case '3': ?? ??? ??? ?printf("返回上级菜单,按任意键继续...\n"); ?? ??? ??? ?return; ?? ??? ?default: ?? ??? ??? ?printf("错误命令!\n");?? ??? ??? ??? ??? ? ?? ??? ?} ?? ??? ?system("pause"); // 调用DOD命令pause使屏幕显示暂停 ?? ?} }
//2、图书入库 void showbookRKMenu() { ?? ?system("cls");? ?? ?printf("%s", bookRKMenu); } void RKBook() { ?? ?Book book; ?? ?inputBook(&book);?? ? ?? ?bookTable.bookArray[bookTable.counts]=book; ?? ?bookTable.index = bookTable.counts; ?? ?bookTable.counts++; ?? ?bookTable.isModified = 1; ?? ?end(); }? void enterbookRK() { ?? ?char cmd; ?? ?while (1) { ?? ??? ?showbookRKMenu(); ?? ??? ?cmd = getchar(); ?? ??? ?getchar(); ?? ??? ?switch (cmd) { ?? ??? ?case '1':?? ??? ??? ?//录入图书信息? ?? ??? ??? ?printf("请安提示录入图书信息");? ?? ??? ??? ?RKBook(); ?? ??? ??? ?break; ?? ??? ?case '2':?? ??? ??? ?//返回(按任意键继续) ?? ??? ??? ?printf("返回上级菜单,按任意键继续...\n"); ?? ??? ??? ?return; ?? ??? ?default: ?? ??? ??? ?printf("错误命令!\n");?? ??? ??? ??? ??? ? ?? ??? ?} ?? ??? ?system("pause"); // 调用DOD命令pause使屏幕显示暂停 ?? ?} }
//3、图书查询 void showbookCXMenu() { ?? ?system("cls");? ?? ?printf("%s", bookCXMenu); }? void enterbookCX() { ?? ?char cmd; ?? ?while (1) { ?? ??? ?showbookCXMenu(); ?? ??? ?cmd = getchar(); ?? ??? ?getchar(); ?? ??? ?switch (cmd) { ?? ??? ?case '1':?? ??? ??? ?//按作者姓名查找 ?? ??? ??? ?AuthorSearchAndPrint(&bookTable); ?? ??? ??? ?break; ?? ??? ?case '2':?? ??? ??? ?//按图书名称查找? ?? ??? ??? ?NameSearchAndPrint(&bookTable); ?? ??? ??? ?break; ?? ??? ?case '3': ?? ??? ??? ?printf("返回上级菜单,按任意键继续...\n"); ?? ??? ??? ?return; ?? ??? ?default: ?? ??? ??? ?printf("错误命令!\n");?? ??? ??? ??? ??? ? ?? ??? ?} ?? ??? ?system("pause"); // 调用DOD命令pause使屏幕显示暂停 ?? ?} }
//4、修改信息 void showbookXGMenu() { ?? ?system("cls");? ?? ?printf("%s", bookXGMenu); }? void modifBook() { ?? ?char name[12]; ?? ?double price; ?? ?int i; ?? ?int number; ?? ?printf("请输入想要修改信息的图书名称:");? ?? ?scanf("%s",name); ?? ?i=searchBookName(name,&bookTable);?? ??? ?//searchBookName()是图书搜索函数? ?? ?printf("请输入新的在库数量:"); ?? ?scanf("%d",&number); ?? ?bookTable.bookArray[i].number=number; ?? ?printf("请输入新的图书价格:"); ?? ?scanf("%lf",&price); ?? ?bookTable.bookArray[i].price=price; ?? ?bookTable.index=1; ?? ?end();?? ??? ?//对信息进行保存? ?? ? } /* void deletBook() { ?? ?char name[12]; ?? ?int i; ?? ?printf("请输入想要删除的图书名称");? ?? ?scanf("%s",name); ?? ?i=searchBookName(name); ?? ?if(i==-1) ?? ?{ ?? ??? ?printf("不存在该图书,或者该图书经被删除了!"); ?? ?} ?? ?else ?? ?{ ?? ??? ?int j; ?? ??? ?for(j=i;j<bookTable.counts;j++) ?? ??? ?{ ?? ??? ??? ?bookTable.bookArray[j]=bookTable.bookArray[j+1]; ?? ??? ?} ?? ??? ? ?? ?} }?? ? */
void enterbookXG() { ?? ?char cmd; ?? ?while (1) { ?? ??? ?showbookXGMenu(); ?? ??? ?cmd = getchar(); ?? ??? ?getchar(); ?? ??? ? ?? ??? ?switch (cmd) { ?? ??? ?case '1':?? ??? ??? ?//修改图书信息? ?? ??? ??? ?modifBook();?? ?//(考虑到图书的基本信息不会变,变化的只能是图书的在库数量) //?? ??? ??? ?end();?? ??? ?//对信息进行保存? ?? ??? ??? ?break; ?? ??? ?case '2':?? ??? ??? ?//删除图书信息? ?? ??? ??? ?bookDelete(&bookTable); ?? ??? ??? ?end(); ?? ??? ??? ?break; ?? ??? ?case '3': ?? ??? ??? ?printf("返回上级菜单,按任意键继续...\n"); ?? ??? ??? ?return; ?? ??? ?default: ?? ??? ??? ?printf("错误命令!\n");?? ??? ??? ??? ??? ? ?? ??? ?} ?? ??? ?system("pause"); // 调用DOD命令pause使屏幕显示暂停 ?? ?} }
//5、帮 ? ?助 void showhelpMenu() { ?? ?system("cls");? ?? ?printf("%s", helpMenu); }? void printhHeple() { ?? ?printf("1、按照系统的提示信息完成所需要进行的步骤\n"); ?? ?printf("2、当按退出的时候,按任意键便可以继续\n"); ?? ?printf("3、需要退到主菜单的时候退出程序\n");? } void printXTxinxi() { ?? ?printf("这是由物联网201班胡俊诚开发,12月1日投入测试的藏书信息管理系统"); ?? ?printf("当前版本为藏书信息管理系统1.0");? } void enterhelp() { ?? ?char cmd; ?? ?while (1) { ?? ??? ?showhelpMenu(); ?? ??? ?cmd = getchar(); ?? ??? ?getchar(); ?? ??? ?switch (cmd) { ?? ??? ?case '1':?? ??? ??? ?//查看帮助 ?? ??? ??? ?printhHeple(); ?? ??? ??? ?break; ?? ??? ?case '2':?? ??? ??? ?// 查看系统信息 ?? ??? ??? ?printXTxinxi(); ?? ??? ??? ?break; ?? ??? ?case '3': ?? ??? ??? ?printf("返回上级菜单,按任意键继续...\n"); ?? ??? ??? ?return; ?? ??? ?default: ?? ??? ??? ?printf("错误命令!\n");?? ??? ??? ??? ??? ? ?? ??? ?} ?? ??? ?system("pause"); // 调用DOD命令pause使屏幕显示暂停 ?? ?} }
//bookTable初始化 void CSH(){ ?? ?Book book1 = {"凡尔纳", "海底两万里", 21.9, 10, {2021,11,30}, ?? ?"主要讲述阿龙纳斯跟随鹦鹉螺号潜艇遨游海洋,在海底进行环球探险旅行的故事"},
?? ??? ? ?? ?book2 = {"查尔斯", "雾都孤儿",19.9, 15, {2021,11,30}, ?? ? "讲述善良的奥利弗经历重重的困难后,雨后见彩红,终于迎来美满的故事结局"}, ?? ? ?? ?book3 = {"雨果", "巴黎圣母院",19.9, 10,{2021,11,30}, ?? ?"巴黎圣母院大教堂是一座位于法国巴黎市中心、西提岛上的天主教的主教堂"}; ?? ?? ?? ?bookTable.bookArray[0] = book1; ?? ?bookTable.bookArray[1] = book2; ?? ?bookTable.bookArray[2] = book3; ?? ?bookTable.counts = 3; ?? ?bookTable.index = 0; ?? ?bookTable.isModified = 0; ?? ?FILE *pf = openTextFileForWrite("Books.txt"); ?? ?if (pf==NULL) ?? ?{ ?? ??? ?puts("打开文件失败!"); ?? ??? ?exit(-1); ?? ?} ?? ?printf("打开成功"); ?? ?outputBookTableToTextFile(pf, &bookTable); ?? ?printf("保存成功"); ?? ?fclose(pf); ?? ? //?? ?printHeader(); //?? ?printBook(&bookTable.bookArray[0]); //?? ?printBook(&bookTable.bookArray[1]); //?? ?printBook(&bookTable.bookArray[2]); }? void start() { ?? ?FILE *pf = openTextFileForRead("Books.txt"); ?? ?if (pf==NULL) ?? ?{ ?? ??? ?puts("打开文件失败!"); ?? ??? ?exit(-1); ?? ?} ?? ?printf("打开成功\n"); ?? ?inputBookTableFromTextFile(pf, &bookTable); //?? ?printHeader(); //?? ?printBook(&bookTable.bookArray[0]); //?? ?printBook(&bookTable.bookArray[1]); //?? ?printBook(&bookTable.bookArray[2]); } void end() { ?? ?FILE *pf = openTextFileForWrite("Books.txt"); ?? ?if (pf==NULL) ?? ?{ ?? ??? ?puts("打开文件失败!"); ?? ??? ?exit(-1); ?? ?} ?? ?printf("打开成功\n"); ?? ?outputBookTableToTextFile(pf,&bookTable); } void main() {
? ??CSH();?? ??? ?//初始化函数? ?? ?start();?? ?//将数据内容从Books.text文件中提取出来? ?? ?run();?? ??? ?//具体运行函数?? ?? ?return; }
注意这是下一个文件-------------------------------------------------------------------------------注意这是下一个文件-------------------------------------------------------------------------------
#ifndef __BOOK_H #define __BOOK_H
typedef struct tagDate { ?? ?int year; ?? ?int month; ?? ?int day; } Date;
typedef struct tagBook { ?? ?char author[12];?? ?//作者姓名? ?? ?char name[12];?? ??? ?//图书名称 ?? ?double price;?? ??? ?//图书价格 ?? ?int number;?? ??? ??? ?//图书入库数量 ?? ?Date Day;?? ??? ??? ?//入库时间? ?? ?char subject[80];?? ?//图书简介 }Book;
#define N 100
typedef struct tagBookTable? { ?? ?Book bookArray[N]; ?? ?// 存放book图书? ?? ?int counts; ? ? ? ?? ?// 数组bookArray中的book图书数量 ?? ?int index; ? ? ? ?? ?// 当前book图书? ?? ?int isModified; ??? ?// 数组bookArray的内容是否变了 }BookTable;
void printHeader();?? ??? ??? ?//打印头信息? //void printAllBook();?? ??? ?//打印汇总的图书信息 //void printBook(); ?? ??? ??? ?//打印图书信息? void printBook(Book *book);?? ?//打印图书的信息? void inputBook(Book *book); //录入图书信息?
#endif
注意这是下一个文件-------------------------------------------------------------------------------
#include <stdio.h> #include "Book.h"
void printHeader() { ?? ?printf("%-12s", "图书作者"); ?? ?printf("%-12s", "图书名称"); ?? ?printf("%-12s", "图书价格"); ?? ?printf("%-12s", "在库数量"); ?? ?printf("%-16s", "入库日期"); ?? ?printf("%-30s\n", "图书简介"); ?? ?printf("-----------------------------------------------------------------------------------\n"); }
void printBook(Book *book) { ?? ?printf("%-12s", book->author); ?? ?printf("%-12s", book->name); ?? ?printf("%-14f", book->price); ?? ?printf("%-10d", book->number); ?? ?printf("%-4d年%-02d月%-02d日\n", book->Day.year, book->Day.month, book->Day.day); ?? ?printf("%-82s\n", book->subject); ?? ?printf("\n"); ?}? ? void inputBook(Book *book) { ?? ?printf("图书作者:"); ?? ?scanf("%s",book->author); ?? ? ?? ?printf("图书名称:"); ?? ?scanf("%s",book->name); ?? ? ?? ?printf("图书价格:"); ?? ?scanf("%lf",&book->price); ?? ? ?? ?printf("入库数量:"); ?? ?scanf("%d",&book->number); ?? ? ?? ?printf("购买日期,年:"); ?? ?scanf("%d", &book->Day.year); ?? ?printf("月:"); ?? ?scanf("%d", &book->Day.month); ?? ?printf("日:"); ?? ?scanf("%d", &book->Day.day); ?? ? ?? ?printf("图书简介:"); ?? ?scanf("%s",book->subject); }
注意这是下一个文件-------------------------------------------------------------------------------
#ifndef __FILE_H #define __FILE_H
#include <stdio.h> #include "Book.h"
FILE *openTextFileForWrite(char *pFileName);?? ?//用只写的方式打开? FILE *openBinaryFileForWrite(char *pFileName);?? ??
FILE *openTextFileForRead(char *pFileName);?? ??? ?//用只读的方式打开? FILE *openBinaryFileForRead(char *pFileName);
void outputBookToTextFile(FILE *pf, Book *book); ?? ?//将数据存储到文件中? void inputBookFromTextFile(FILE *pf, Book *book);?? ?//将文件的数据读取?
void outputBookTableToTextFile(FILE *pf, BookTable *bookTable); void inputBookTableFromTextFile(FILE *pf, BookTable *bookTable);
#endif 注意这是下一个文件-------------------------------------------------------------------------------
#include "File.h" #include "Book.h"
FILE *openTextFileForWrite(char *pFileName) { ?? ?FILE *fp = fopen(pFileName, "wt"); ?? ?return fp; }
FILE *openBinaryFileForWrite(char *pFileName) { ?? ?FILE *fp = fopen(pFileName, "wb"); ?? ?return fp; }
FILE *openTextFileForRead(char *pFileName) { ?? ?FILE *fp = fopen(pFileName, "rt"); ?? ?return fp; }
FILE *openBinaryFileForRead(char *pFileName) { ?? ?FILE *fp = fopen(pFileName, "rb"); ?? ?return fp; }
void outputBookToTextFile(FILE *pf,Book *book) { ?? ?fprintf(pf, "%-12s", book->author); ?? ?fprintf(pf, "%-12s", book->name); ?? ?fprintf(pf, "%-14lf", book->price); ?? ?fprintf(pf, "%-10d", book->number); ?? ?fprintf(pf,"%-4d年%-02d月%-02d日 ", book->Day.year, book->Day.month, book->Day.day); ?? ?fprintf(pf, "%-82s\n", book->subject);? ?? ? } void inputBookFromTextFile(FILE *pf, Book *book) { ?? ?fscanf(pf, "%s", book->author);? ?? ?fscanf(pf, "%s", book->name); ?? ?fscanf(pf, "%lf",&book->price); ?? ?fscanf(pf, "%d", &book->number); ?? ?fscanf(pf, "%d", &book->Day.year); ?? ?getc(pf); ?? ?getc(pf); ?? ?fscanf(pf, "%d", &book->Day.month); ?? ?getc(pf); ?? ?getc(pf); ?? ?fscanf(pf, "%d", &book->Day.day); ?? ?getc(pf); ?? ?getc(pf); ?? ?fscanf(pf, "%s", book->subject); ?? ? }
void outputBookTableToTextFile(FILE *pf, BookTable *bookTable) { ?? ?int n = bookTable->counts; ?? ?int i=0; ?? ?while (i<n) ?? ?{ ?? ??? ?outputBookToTextFile(pf, &bookTable->bookArray[i]); ?? ??? ?i++; ?? ?} }
void inputBookTableFromTextFile(FILE *pf, BookTable *bookTable) { ?? ?int n = 0; ?? ?Book book; ?? ?inputBookFromTextFile(pf, &book); ?? ?while (!feof(pf)) ?? ?{ ?? ??? ?bookTable->bookArray[n] = book; ?? ??? ?n++; ?? ??? ?inputBookFromTextFile(pf, &book); ?? ?} ?? ?bookTable->counts = n; ?? ?bookTable->index = 0; ?? ?bookTable->isModified = 0; }
注意这是下一个文件-------------------------------------------------------------------------------
#ifndef __SEARCH_H #define __SEARCH_H
#include <stdio.h> #include<string.h> #include "Book.h"
int searchBookName(char *name,BookTable *bookTable); int searchAuthorName(char *author,BookTable *bookTable);
void AuthorSearchAndPrint(BookTable *bookTable); void NameSearchAndPrint(BookTable *bookTable); void bookDelete(BookTable *bookTable); #endif
注意这是下一个文件-------------------------------------------------------------------------------
#include "Search.h" int searchBookName(char *name,BookTable *bookTable)?? ?//搜索图书名称查找位置? { ?? ?int i=0;?? ?? //?? ?char name[12];?? ? //?? ?printf("请输入你需要查找的图书:"); //?? ?scanf("%s",name); ?? ?int counts= bookTable->counts; ?? ?while(i<counts)?? ? ?? ?{ ?? ??? ?int str; ?? ??? ?str=strcmp(name, bookTable->bookArray[i].name); ?? ??? ?if(str==0) ?? ??? ?{ ?? ??? ??? ?return i;?? ?//返回的i,为书在bookArray[]中的序号? ?? ??? ?} ?? ??? ?i++; ?? ?} ?? ?return -1;?? ??? ?//返回-1时,说明系统中没有该图书? ?? ? } int searchAuthorName(char *author,BookTable *bookTable)?? ?//搜索作者名字查找位置? { ?? ?int i=0; //?? ?char author[12]; //?? ?printf("请输入你需要查找的作者名字:"); //?? ?scanf("%s",author); ?? ?int counts= bookTable->counts; ?? ?while(i<counts)?? ? ?? ?{ ?? ??? ?int str; ?? ??? ?str=strcmp(author, bookTable->bookArray[i].author); ?? ??? ?if(str==0) ?? ??? ?{ ?? ??? ??? ?return i;?? ?//返回的i,为作者在bookArray[]中的序号? ?? ??? ?} ?? ??? ?i++; ?? ?} ?? ?return -1;?? ??? ?//返回-1时,说明系统中没有该作者的图书? ?? ? }
void AuthorSearchAndPrint(BookTable *bookTable)?? ??? ?//搜索打印? { ?? ? ?? ?int i=0; ?? ?char author[12]; ?? ?printf("请输入你需要查找的作者名字:"); ?? ?scanf("%s",author); ?? ?i=searchAuthorName(author,bookTable); ?? ?if(i==-1) ?? ?{ ?? ??? ?printf("系统中没有该作者的图书"); ?? ?} ?? ?else ?? ?{ ?? ??? ?printHeader(); ?? ??? ?printBook(&bookTable->bookArray[i]); ?? ?} }? void NameSearchAndPrint(BookTable *bookTable)?? ??? ?//搜索打印 { ?? ? ?? ?int i=0; ?? ?char name[12];?? ? ?? ?printf("请输入你需要查找的图书:"); ?? ?scanf("%s",name); ?? ?i=searchAuthorName(name,bookTable); ?? ?if(i==-1) ?? ?{ ?? ??? ?printf("系统中没有该图书"); ?? ?} ?? ?else ?? ?{ ?? ??? ?printHeader(); ?? ??? ?printBook(&bookTable->bookArray[i]); ?? ?} } void bookDelete(BookTable *bookTable)? { ?? ?int i=0; ?? ?char name[12];?? ? ?? ?printf("请输入你想要删除的图书:"); ?? ?scanf("%s",name); ?? ?i=searchAuthorName(name,bookTable); ?? ?if(i==-1) ?? ?{ ?? ??? ?printf("系统中没有该图书"); ?? ?} ?? ?else ?? ?{ ?? ??? ?for(i;i<bookTable->counts;i++) ?? ??? ?{ ?? ??? ??? ?bookTable->bookArray[i]=bookTable->bookArray[i+1]; ?? ??? ?} ?? ??? ? ?? ?} ?? ? }
|