C語言圖書管理系統
阿新 • • 發佈:2019-02-17
本人也才學C語言,程式碼有在網上借鑑的,自己完善和添加了幾個功能。
#include<stdio.h>
#include<stdlib.h>#include<string.h>
#include<conio.h>
#include<windows.h>
#include<stdio.h>//
#include<stdlib.h>//
#include<string.h>
#include<time.h>
#include<Windows.h>//顏色需求
//#define FilePath "couen.txt"
void guihuan(struct book *head);
struct d
{
char name[100];
char mima[100];
};
d p, q, m;
typedef struct enter
{
d xx;
struct enter *next;
}E;
char root[] = "root";
char roo[] = "123";
void en()
{
FILE *fp;
d bookinfo[20];
d l;
int n = 1, x = 1;
int g = 0;
int booknumber = 0;
if ((fp = fopen("couen.txt", "rb")) == NULL)
printf("失敗");
while (!feof(fp))
{
fread(&bookinfo[booknumber], sizeof(d), 1, fp);
booknumber++;
}
booknumber--;
fclose(fp);
while (n)
{
char a[100], b[100];
printf(" 請輸入你的使用者名稱 \n");
scanf("%s", a);
printf(" 請輸入你的密碼 \n");
scanf("%s", b);
system("cls");
/*booknumber--;使用feof()函式會多讀一行,因此需要booknumber自減一次,使書目的數量正確*/
strcpy(l.name, a);
strcpy(l.mima, b);
system("pause");
for (g = 0; g <= booknumber; g++)
{
if (strcmp(l.name, bookinfo[g].name) == 0 && strcmp(l.mima, bookinfo[g].mima) == 0)
{
printf("驗證正確\n");
system("cls");
printf("正在進入系統請稍後.\n");
_sleep(500);
system("cls");
printf("正在進入系統請稍後..\n");
_sleep(500);
system("cls");
printf("正在進入系統請稍後...\n");
_sleep(500);
system("cls");
printf("正在進入系統請稍後.\n");
_sleep(500);
system("cls");
printf("正在進入系統請稍後..\n");
_sleep(500);
system("cls");
printf("正在進入系統請稍後...\n");
n = 0;
x = 2;
break;
system("cls");
}
}
if (x == 1)
{
printf("請檢查賬戶或密碼是否正確\n");
printf("然後重新輸入\n");
system("pause");
}
}
}
void zc()
{
int t = 1;
E *hea;
char a[100], b[100], c[] = "123";
FILE* fp;
if ((fp = fopen("couen.txt", "ab")) == NULL)
{
printf("無法建立計數器檔案!\n");
return;
}
fp = fopen("couen.txt", "ab");
printf(" 請輸入你想要的的使用者名稱 \n");
scanf("%s", a);
printf(" 請輸入你想要的密碼 \n");
scanf("%s", b);
strcpy(p.name, a);
strcpy(p.mima, b);
fwrite(&p, sizeof(d), 1, fp);
fclose(fp);
}
struct book {
int num;
char bname[50];
char wname[20];
char press[50];
char sort[50];
int time;
float price;
int islended;
int counter;
struct book *next;
};
int gotoxy(int x, int y)
{
HANDLE hout;
COORD coord;
coord.X = x;
coord.Y = y;
hout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hout, coord);
return 0;
}
void jieshu(struct book *head);
void paixu();
struct book *creatbook(); //建立連結串列
struct book *addbook(struct book *head); //新增圖書
int yanzheng(struct book *head, int m); //驗證新新增的圖書編碼是否已存在
void deletebook(struct book *head); //刪除圖書
void fprint(struct book *head); //將連結串列寫入檔案
struct book *load(); //從檔案中讀取資訊並建成連結串列
void print_book(struct book *head); //將連結串列資訊輸出
void chaxun(struct book *head); //查詢圖書資訊
void num_chaxun(struct book *head); //按圖書編號查詢圖書
void wname_chaxun(struct book *head); //按作者名查詢圖書
void sort_chaxun(struct book *head); //按類別查詢圖書
void time_chaxun(struct book *head); //按出版時間查詢圖書
void bname_chaxun(struct book *head); //按圖書名查詢圖書
void xiugai(struct book *head); //修改圖書資訊
int main()
{
int m, cv = 1;
system("color 4a");
printf("\n\n\n\n\n");
printf(" \t\t\t 登入介面 \n\n");
printf(" \t\t\t|----------------------------|\n");
printf(" \t\t\t| 有賬戶可登入,(沒有請註冊 | \n");
printf(" \t\t\t| 按 1進入登入 | \n");
printf(" \t\t\t| 按 2進入註冊 | \n");
printf(" \t\t\t| 按 3第三方登入 |\n");
printf(" \t\t\t|----------------------------|\n");
while (cv)
{
scanf("%d", &m);
switch (m)
{
case 1:
en();
cv = 0;
break;
case 2:zc();
cv = 0;
printf("註冊成功將自動退出請重新登入\n");
system("pause");
exit(1);
break;;
case 3:
printf("按1 微信登入\n");
printf("按2 qq登入\n");
printf("按3 微博登入\n");
system("pause");
printf("當然是騙你的了\n");
system("pause");
cv = 0;
exit(1);
break;
default:
printf("輸入錯誤請重新輸入\n");
break;
}
}
char key, z;
int o = 40, p = 4;
int choice, x;
char a, d, b[10], b1[10], c1[10], c[10];
struct book *head = NULL;
while (1)
{
system("cls");
system("color 4a");
printf("\n");
system("cls");
system("color 4a");
printf(" ----------------------圖書管理系統-----------------------\n");
printf(" ---------------------------------------------------------\n");
printf(" |\t\t 1 新增圖書\t\t\t\t|\n");
printf(" |\t\t 2 刪除圖書\t\t\t\t|\n");
printf(" |\t\t 3 圖書列表\t\t\t\t|\n");
printf(" |\t\t 4 查詢圖書\t\t\t\t|\n");
printf(" |\t\t 5 修改圖書\t\t\t\t|\n");
printf(" |\t\t 6 錄入資料\t\t\t\t|\n");
printf(" |\t\t 7 借閱圖書\t\t\t\t|\n");
printf(" |\t\t 8 歸還圖書\t\t\t\t|\n");
printf(" |\t\t 9 借閱排行\t\t\t\t|\n");
printf(" |\t\t 0 退出系統\t\t\t\t|\n");
printf(" ---------------------------------------------------------\n");
printf("\t\t\t\t請輸入所選擇的序號:");
scanf("%d", &choice);
getchar();
system("cls");
switch (choice)
{
case 7:
head = load();
jieshu(head);
fprint(head);
getchar();
break;
case 8:
head = load();
guihuan(head);
fprint(head);
system("pause");
break;
case 9:
head = load();
paixu();
fprint(head);
getchar();
break;
case 0:
x = 0; break;
case 1:
head = load();
if (head == NULL) {
printf("檔案為空,請先錄入資料!\n");
getchar();
break;
}
else {
head = addbook(head);
printf("新增成功!\n");
printf("是否將新資訊儲存到檔案?(e/n)\n");
scanf("%c", &a);
getchar();
switch (a) {
case 'n':
break;
case 'e':
fprint(head);
printf("儲存成功!\n");
getchar();
break;
}
break;
}
case 2:
head = load();
if (head == NULL) {
printf("檔案為空,請先錄入資料!\n");
getchar();
break;
}
else {
deletebook(head);
getchar();
break;
}
break;
case 3:
head = load();
if (head == NULL) {
printf("檔案為空,請先錄入資料!\n");
getchar();
break;
}
else {
print_book(head);
getchar();
break;
}
case 4:
head = load();
if (head == NULL) {
printf("檔案為空,請先錄入資料!\n");
getchar();
break;
}
else {
chaxun(head);
getchar();
}
break;
case 5:
head = load();
if (head == NULL) {
printf("檔案為空,請先錄入資料!\n");
getchar();
break;
}
else {
xiugai(head);
getchar();
break;
}
break;
case 6:
printf("注意:輸入圖書編碼為0時結束!\n");
head = creatbook();
printf("是否將輸入的資訊儲存到檔案以覆蓋檔案中已存在的資訊?(e/n)\n");
getchar();
scanf("%c", &a);
getchar();
switch (a) {
case 'n':
break;
case 'e':
fprint(head);
printf("儲存成功!\n");
getchar();
break;
}
break;
default:
printf("您的輸入有誤,請重新輸入!\n");
getchar();
break;
}
}
}
//錄入資料並形成連結串列
void paixu()
{
struct book *ptr;
struct book *list;
list = load();
struct book *p, *q;
int t;
int num;
char bname2[50];
for (p = list; p != NULL; p = p->next)
{
for (q = p->next; q != NULL; q = q->next)
{
if (p->counter<q->counter)//降序
{
t = q->counter;
q->counter = p->counter;
p->counter = t;
t = q->num;
q->num = p->num;
p->num = t;
strcpy(bname2, p->bname);
strcpy(p->bname, q->bname);
strcpy(q->bname, bname2);
}
}
}
ptr = list;
while (ptr)
{
printf(" 編號\t圖書名\t次數\n");
printf(" %d\t%s\t%d\n", ptr->num, ptr->bname, ptr->counter);
ptr = ptr->next;
}
}
struct book *creatbook()
{
char r[50];
char ro[50];
printf("需要管理員許可權\n請登入\n");
printf("賬戶\n");
scanf("%s", r);
printf("密碼\n");
scanf("%s", ro);
if (strcmp(r, root) != 0 && strcmp(roo, ro) != 0)
{
printf("你不是管理員\n系統將自動退出");
system("pause");
exit(1);
}
struct book *head, *tail, *p;
int num, time, n;
char bname[50], wname[20], press[50], sort[50];
float price;
int size = sizeof(struct book);
head = tail = NULL;
printf("請輸入圖書編號:");
scanf("%d", &num);
printf("請輸入圖書名:");
scanf("%s", bname);
getchar();
printf("請輸入作者名:");
scanf("%s", wname);
getchar();
printf("請輸入出版社:");
scanf("%s", press);
getchar();
printf("請輸入類別:");
scanf("%s", sort);
getchar();
printf("請輸入出版時間:");
scanf("%d", &time);
getchar();
printf("請輸入價格:");
scanf("%f", &price);
getchar();
while (1) {
p = (struct book *)malloc(size);
p->num = num;
strcpy(p->bname, bname);
strcpy(p->wname, wname);
strcpy(p->press, press);
strcpy(p->sort, sort);
p->time = time;
p->price = price;
p->counter = 0;
p->next = NULL;
if (head == NULL)
head = p;
else
tail->next = p;
tail = p;
do {
printf("請輸入圖書編號:");
scanf("%d", &num);
n = yanzheng(head, num);
if (n == 0)
break;
else
printf("您輸入的編號已存在,請重新輸入!\n");
} while (1);
if (num == 0)
break;
else
{
printf("請輸入圖書名:");
scanf("%s", bname);
getchar();
printf("請輸入作者名:");
scanf("%s", wname);
getchar();
printf("請輸入出版社:");
scanf("%s", press);
getchar();
printf("請輸入類別:");
scanf("%s", sort);
getchar();
printf("請輸入出版時間:");
scanf("%d", &time);
getchar();
printf("請輸入價格:");
scanf("%f", &price);
getchar();
}
}
return head;
}
//插入節點,並且插入後仍按一定順序
struct book *addbook(struct book *head)
{
char r[50];
char ro[50];
printf("需要管理員許可權\n請登入\n");
printf("賬戶\n");
scanf("%s", r);
printf("密碼\n");
scanf("%s", ro);
if (strcmp(r, root) != 0 && strcmp(roo, ro) != 0)
{
printf("你不是管理員\n系統將自動退出");
system("pause");
exit(1);
}
struct book *ptr, *p1, *p2, *p;
char bname[50], wname[20], press[50], sort[50];
int size = sizeof(struct book);
int num, time, n = 1;
float price;
do {
printf("請輸入圖書編號:");
scanf("%d", &num);
n = yanzheng(head, num);
if (n == 0)
break;
else
printf("您輸入的編號已存在,請重新輸入!\n");
} while (1);
printf("請輸入圖書名:");
scanf("%s", bname);
getchar();
printf("請輸入作者名:");
scanf("%s", wname);
getchar();
printf("請輸入出版社:");
scanf("%s", press);
getchar();
printf("請輸入類別:");
scanf("%s", sort);
getchar();
printf("請輸入出版時間:");
scanf("%d", &time);
getchar();
printf("請輸入價格:");
scanf("%f", &price);
getchar();
p = (struct book *)malloc(size);
p->num = num;
strcpy(p->bname, bname);
strcpy(p->wname, wname);
strcpy(p->press, press);
strcpy(p->sort, sort);
p->time = time;
p->price = price;
p->counter = 0;
p2 = head;
ptr = p;
while ((ptr->num>p2->num) && (p2->next != NULL)) {
p1 = p2;
p2 = p2->next;
}
if (ptr->num <= p2->num) {
if (head == p2)
head = ptr;
else {
p1->next = ptr;
p->next = p2;
}
}
else {
p2->next = ptr;
p->next = NULL;
}
return head;
}
//驗證新增的圖書編號是否已存在
int yanzheng(struct book *head, int m)
{
struct book *p;
p = head;
while (p != NULL)
{
if (p->num == m)
break;
p = p->next;
}
if (p == NULL)
return 0;
else
return 1;
}
//從檔案中讀取圖書資訊
struct book *load()
{
FILE *fp;
char ch;
struct book *head, *tail, *p1;
head = tail = NULL;
if ((fp = fopen("f1.txt", "r")) == NULL) {
printf("File open error!\n");
exit(0);
}
ch = fgetc(fp);
if (ch == '1') {
while (!feof(fp)) {
p1 = (struct book *)malloc(sizeof(struct book));
fscanf(fp, "%d%s%s%s%s%d%f%d\n", &p1->num, p1->bname, p1->wname, p1->press, p1->sort, &p1->time, &p1->price, &p1->counter);
if (head == NULL)
head = p1;
else
tail->next = p1;
tail = p1;
}
tail->next = NULL;
fclose(fp);
return head;
}
else
return NULL;
}
//將整個連結串列的資訊輸出
void print_book(struct book *head)
{
struct book *ptr;
if (head == NULL) {
printf("\n沒有資訊!\n");
return;
}
printf(" 圖書資訊如下\n");
printf(" ==========================================================\n");
printf(" 編號\t圖書名\t作者名\t出版社\t類別\t出版時間\t價格\n");
for (ptr = head; ptr; ptr = ptr->next)
printf(" %d\t%s\t%s\t%s\t%s\t%d\t\t%.2f\n", ptr->num, ptr->bname, ptr->wname, ptr->press, ptr->sort, ptr->time, ptr->price);
printf(" ==========================================================\n");
}
//刪除圖書資訊
void deletebook(struct book *head)
{
char r[50];
char ro[50];
printf("需要管理員許可權\n請登入\n");
printf("賬戶\n");
scanf("%s", r);
printf("密碼\n");
scanf("%s", ro);
if (strcmp(r, root) != 0 && strcmp(roo, ro) != 0)
{
printf("你不是管理員\n系統將自動退出");
system("pause");
exit(1);
}
int a;
char b, ch = '1';
struct book *p1, *p2;
FILE *fp;
printf("請輸入要刪除的圖書編號:");
scanf("%d", &a);
p1 = head;
if (p1->num == a&&p1->next == NULL) { //對於檔案中只有一組資料
printf("是否清空檔案!(y/n)\n");
getchar();
scanf("%c", &b);
getchar();
switch (b) {
case 'n':
break;
case 'y':
if ((fp = fopen("f1.txt", "w")) == NULL) {
printf("File open error!\n");
exit(0);
}
fclose(fp);
printf("檔案已清空!\n");
}
}
else {
while (p1->num != a&&p1->next != NULL) {
p2 = p1;
p1 = p1->next;
}
if (p1->next == NULL) {
if (p1->num == a) {
p2->next = NULL;
printf("是否確定從檔案中徹底刪除該圖書?(y/n)\n");
getchar();
scanf("%c", &b);
switch (b) {
case 'n':
break;
case 'y':
fprint(head);
printf("刪除成功!\n");
getchar();
break;
}
}
else {
printf("沒有找到要刪除的資料!\n");
getchar();
}
}
else if (p1 == head) {
head = p1->next;
printf("是否確定從檔案中徹底刪除該圖書?(y/n)\n");
getchar();
scanf("%c", &b);
switch (b) {
case 'n':
break;
case 'y':
fprint(head);
printf("刪除成功!\n");
getchar();
break;
}
}
else {
p2->next = p1->next;
printf("是否確定從檔案中徹底刪除該圖書?(y/n)\n");
getchar();
scanf("%c", &b);
switch (b) {
case 'n':
break;
case 'y':
fprint(head);
printf("刪除成功!\n");
getchar();
break;
}
}
}
}
//圖書查詢
void chaxun(struct book *head)
{
int a;
printf(" ==========================================================\n");
printf(" | 1-按圖書編號查詢 2-按圖書名查詢 | \n");
printf(" | 3-按圖書類別查詢 4-按作者名查詢 | \n");
printf(" | 5-按出版時間查詢 0-退出查詢 | \n");
printf(" ==========================================================\n");
printf("請輸入所選擇的編號:");
scanf("%d", &a);
getchar();
switch (a) {
case 0:
break;
case 1:
num_chaxun(head);
break;
case 2:
bname_chaxun(head);
break;
case 3:
sort_chaxun(head);
break;
case 4:
wname_chaxun(head);
break;
case 5:
time_chaxun(head);
break;
default:
printf("您的輸入有誤!\n");
break;
}
}
//按編號查詢圖書資訊
void num_chaxun(struct book *head)
{
int a;
struct book *p;
printf("請選擇您要查詢的圖書編號:");
scanf("%d", &a);
getchar();
p = head;
while (p != NULL) {
if (p->num == a)
break;
p = p->next;
}
if (p == NULL) {
printf("沒有找到該編號的圖書!\n");
}
else {
printf(" 你所查詢的圖書資訊如下\n");
printf(" =========================================================================\n");
printf(" 編號 圖書名 作者名 出版社 類別 出版時間 價格 \n");
printf(" %d %s %s %s %s %d %.2f \n", p->num, p->bname, p->wname, p->press, p->sort, p->time, p->price);
printf(" =========================================================================\n");
}
}
void jieshu(struct book *head)
{
int choice;
char a[50];
int flag = 0;
struct book *p;
printf("請選擇您要查詢的圖書名:");
scanf("%s", a);
p = head;
while (p != NULL) {
if (strcmp(p->bname, a) == 0) {
flag = 1;
break;
}
p = p->next;
}
if (flag == 0) {
printf("沒有找到該圖書名的圖書!\n");
}
else {
printf(" 你所查詢的圖書資訊如下\n");
printf(" =========================================================================\n");
printf(" ** 編號 圖書名 作者名 出版社 類別 出版時間 價格 **\n");
while (p != NULL) {
if (strcmp(p->bname, a) == 0) {
printf(" ** %d %s %s %s %s %d %.2f **\n", p->num, p->bname, p->wname, p->press, p->sort, p->time, p->price);
printf("是否借閱書籍?\n");
printf("1 是 2否\n");
scanf("%d", &choice);
switch (choice)
{
case 1:p->islended = 1;
printf("%d", p->counter);
p->counter++;
printf("%d", p->counter);
printf("借閱成功\n");
break;
}
}
p = p->next;
}
printf(" =========================================================================\n");
}
}
//將新連結串列寫入檔案中
void fprint(struct book *head)
{
FILE *fp;
char ch = '1';
struct book *p1;
if ((fp = fopen("f1.txt", "wb")) == NULL) {
printf("File open error!\n");
exit(0);
}
fputc(ch, fp);
for (p1 = head; p1; p1 = p1->next) {
fprintf(fp, "%d %s %s %s %s %d %f %d\n", p1->num, p1->bname, p1->wname, p1->press, p1->sort, p1->time, p1->price, p1->counter);
}
fclose(fp);
}
//按圖書名查詢圖書資訊
void bname_chaxun(struct book *head)
{
char a[50];
int flag = 0;
struct book *p;
printf("請選擇您要查詢的圖書名:");
scanf("%s", a);
p = head;
while (p != NULL) {
if (strcmp(p->bname, a) == 0) {
flag = 1;
break;
}
p = p->next;
}
if (flag == 0) {
printf("沒有找到該圖書名的圖書!\n");
}
else {
printf(" 你所查詢的圖書資訊如下\n");
printf(" =========================================================================\n");
printf(" ** 編號 圖書名 作者名 出版社 類別 出版時間 價格 **\n");
while (p != NULL) {
if (strcmp(p->bname, a) == 0) {
printf(" ** %d %s %s %s %s %d %.2f **\n", p->num, p->bname, p->wname, p->press, p->sort, p->time, p->price);
}
p = p->next;
}
printf(" =========================================================================\n");
}
}
//按作者名查詢圖書資訊
void wname_chaxun(struct book *head)
{
char a[50];
int flag = 0;
struct book *p;
printf("請選擇您要查詢的圖書作者名:");
scanf("%s", a);
p = head;
while (p != NULL) {
if (strcmp(p->wname, a) == 0) {
flag = 1;
break;
}
p = p->next;
}
if (flag == 0) {
printf("沒有找到該圖書名的圖書!\n");
}
else {
printf(" 你所查詢的圖書資訊如下\n");
printf(" =========================================================================\n");
printf(" ** 編號 圖書名 作者名 出版社 類別 出版時間 價格 **\n");
while (p != NULL) {
if (strcmp(p->wname, a) == 0) {
printf(" ** %d %s %s %s %s %d %.2f **\n", p->num, p->bname, p->wname, p->press, p->sort, p->time, p->price);
flag = 1;
}
p = p->next;
}
printf(" =========================================================================\n");
}
}
//按圖書類別查詢圖書資訊
void sort_chaxun(struct book *head)
{
char a[50];
int flag = 0;
struct book *p;
printf("請選擇您要查詢的圖書類別:");
scanf("%s", a);
p = head;
while (p != NULL) {
if (strcmp(p->sort, a) == 0) {
flag = 1;
break;
}
p = p->next;
}
if (flag == 0) {
printf("沒有找到該圖書名的圖書!\n");
}
else {
printf(" 你所查詢的圖書資訊如下\n");
printf(" =========================================================================\n");
printf(" ** 編號 圖書名 作者名 出版社 類別 出版時間 價格 **\n");
while (p != NULL) {
if (strcmp(p->sort, a) == 0) {
printf(" ** %d %s %s %s %s %d %.2f **\n", p->num, p->bname, p->wname, p->press, p->sort, p->time, p->price);
flag = 1;
}
p = p->next;
}
printf(" =========================================================================\n");
}
}
//按圖書出版時間查詢圖書資訊
void time_chaxun(struct book *head)
{
int a, flag = 0;
struct book *p;
printf("請選擇您要查詢的圖書出版時間:");
scanf("%d", &a);
getchar();
p = head;
while (p != NULL) {
if (p->time == a) {
flag = 1;
break;
}
p = p->next;
}
if (flag == 0) {
printf("沒有找到該圖書名的圖書!\n");
}
else {
printf(" 你所查詢的圖書資訊如下\n");
printf(" =========================================================================\n");
printf(" ** 編號 圖書名 作者名 出版社 類別 出版時間 價格 **\n");
while (p != NULL) {
if (p->time == a) {
printf(" ** %d %s %s %s %s %d %.2f **\n", p->num, p->bname, p->wname, p->press, p->sort, p->time, p->price);
flag = 1;
}
p = p->next;
}
printf(" =========================================================================\n");
}
}
//修改圖書資訊
void xiugai(struct book *head)
{
int a, b;
char c;
struct book *p;
printf("請輸入要修改的圖書編號:");
scanf("%d", &a);
p = head;
while (p != NULL) {
if (p->num == a)
break;
p = p->next;
}
if (p == NULL) {
printf("沒有找到該編號的圖書!\n");
getchar();
}
else {
printf(" ============================================================\n");
printf(" | 1-編號 2-圖書名 3-作者名 |\n");
printf(" | 4-出版社 5-類別 6-出版時間 |\n");
printf(" | 7-價格 8-修改全部 0-放棄修改 |\n");
printf(" ============================================================\n");
printf("請選擇你要修改的資訊編號:");
scanf("%d", &b);
getchar();
switch (b) {
case 1:
printf("請輸入新編號:");
scanf("%d", &p->num);
printf("修改成功!\n");
getchar();
break;
case 2:
printf("請輸入新圖書名:");
scanf("%s", p->bname);
printf("修改成功!\n");
break;
case 3:
printf("請輸入新作者名:");
scanf("%s", p->wname);
printf("修改成功!\n");
break;
case 4:
printf("請輸入新出版社:");
scanf("%s", p->press);
printf("修改成功!\n");
break;
case 5:
printf("請輸入新類別:");
scanf("%s", p->sort);
printf("修改成功!\n");
break;
case 6:
printf("請輸入新出版時間:");
scanf("%d", &p->time);
printf("修改成功!\n");
getchar();
break;
case 7:
printf("請輸入新價格:");
scanf("%f", &p->price);
printf("修改成功!\n");
getchar();
break;
case 8:
printf("請輸入新圖書編號:");
scanf("%d", &p->num);
printf("請輸入新圖書名:");
scanf("%s", p->bname);
getchar();
printf("請輸入新作者名:");
scanf("%s", p->wname);
getchar();
printf("請輸入新出版社:");
scanf("%s", p->press);
getchar();
printf("請輸入新類別:");
scanf("%s", p->sort);
getchar();
printf("請輸入新出版時間:");
scanf("%d", &p->time);
getchar();
printf("請輸入新價格:");
scanf("%f", &p->price);
getchar();
printf("修改成功!\n");
getchar();
break;
case 0:
break;
default:
printf("您的輸入有誤!\n");
break;
}
printf("是否將修改後的資訊儲存到檔案中?(y/n)\n");
scanf("%c", &c);
getchar();
switch (c) {
case 'n':
break;
case 'y':
fprint(head);
printf("儲存成功!\n");
getchar();
break;
}
}
}
void guihuan(struct book *head) //歸還圖書
{
int cunzai = 0;
int choice;
char a[50];
int flag = 0;
struct book *p;
printf("請輸入您要歸還的圖書名:");
scanf("%s", a);
p = head;
while (p != NULL)
{
if (strcmp(p->bname, a) == 0)
{
flag = 1;
break;
}
p = p->next;
}
if (flag == 0) {
printf("沒有找到該圖書名的圖書!\n");
}
else {
printf(" 你所要歸還的圖書資訊如下\n");
printf(" =========================================================================\n");
printf(" ** 編號 圖書名 作者名 出版社 類別 出版時間 價格 **\n");
while (p != NULL) {
if (strcmp(p->bname, a) == 0) {
printf(" ** %d %s %s %s %s %d %.2f **\n", p->num, p->bname, p->wname, p->press, p->sort, p->time, p->price);
printf("是否歸還書籍?\n");
printf("1 是 2否\n");
scanf("%d", &choice);
switch (choice)
{
case 1:p->islended = 0;
printf("歸還成功\n");
break;
}
}
p = p->next;
}
}
}