巨大bug
//數據結構關于課程設計--------圖書館管理系統的設計
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define _OJ_typedef struct Book
{char title[30];//ISBN編號書籍的標準編號char ISBN[30];char author[30]; //作者char publisher[30]; //出版社char pub_time[30]; //出版時間char price[10]; //書的價格int count; //書的數量struct Book *next; } Book, *Linkbook;typedef struct Student
{int amount; //學生已借書的數量char stu_num[8]; //學生的學號char name[20]; //學生的姓名char card_num[8]; //借書證的編號Linkbook stu_book[6]; //學生所借圖書信息 struct Student *next;
} Stu, *Linkstu;//判斷輸入的字符是否正確
void
input_str(const char *str, char *str1, int number)
{char tmp[200];printf("%s", str);do {scanf("%s", tmp);if(strlen(tmp) > number) {printf("您輸入的信息錯誤請重新輸入:\n");}} while(strlen(tmp) > number);strcpy(str1, tmp);
}// 判斷輸入的整型數字是否正確
int
input_float(const char *str, char *str1, int number)
{int i, len, flag;char num[200];printf("%s", str);for ( ; ;) {flag = 0;scanf("%s", num);len = strlen(num);if(len > number) {printf("\n您輸入的信息錯誤請重新輸入:");continue;}for (i = 0; i < len; i++) {if((num[i] < '0' || num[i] > '9') && num[i] != '.') {printf("\n您輸入的不是浮點數字請重新輸入:");flag = 1; break;}}if(flag == 1) continue;elsebreak;}strcpy(str1, num);return 1;
}//------------------------------------- 判斷輸入的浮點型是否正確
int
input_int(const char *str, int number)
{int i, len, flag;char num[200];printf("%s", str);for ( ; ;) {flag = 0;scanf("%s", num);len = strlen(num);if(len > number) {printf("\n您輸入的數字超限請重新輸入:");continue;}for (i = 0; i < len; i++) {if((num[i] < '0' || num[i] > '9')) {printf("\n您輸入的非數字或不是整型數字請重新輸入:");flag = 1; break;}}if(flag == 1) continue;elsebreak;}int n = atoi(num);return n;
}//-----------------------------------------------判斷輸入的ISBN是否正確
void
input_ISBN(const char *str, char *str1) //International Standard Book Number
{int i, flag;char tmp[200]; //x-xxx-xxxxx-xprintf("%s", str);for(;;) {flag = 0;scanf("%s", tmp);if(strlen(tmp) != 13 || tmp[1] != '-' || tmp[5] != '-' || tmp[11] != '-') {printf("您輸入的格式錯誤請重新輸入格式為:x-xxx-xxxxx-x\n");continue; }for( i = 0; i < strlen(tmp); i++) {if((tmp[i] < '0' || tmp[i] > '9') && tmp[i] != '-'){printf("您輸入的含非數字請重新輸入格式為:x-xxx-xxxxx-x");flag = 1; continue;} } if(flag == 1) continue;elsebreak;}strcpy(str1, tmp);
}//-----------------------------------------------------------------------------
//書籍收編入庫
Linkbook
Creat_book(void)
{char ch;Linkbook L, head, P;head = (Linkbook) malloc (sizeof(Book));if(!head) {printf("申請空間失敗!!!\n"); exit(0);}L = head;printf("創建圖書:\n");for (;;) {P = (Linkbook) malloc (sizeof(Book)); P->next = NULL;input_str("請輸圖書名稱:", P->title, 30);input_str("請輸入圖書的作者:", P->author, 30); input_str("請輸入圖書的出版社:", P->publisher, 30);input_str("請輸入圖書的出版時間:", P->pub_time, 30);input_float("請輸入圖書的價格:", P->price, 10);P->count = input_int("請輸入圖書的數量:",5);input_ISBN("請輸入圖書的ISBN格式為:x-xxx-xxxxx-x:\n", P->ISBN);L->next = P; L = P;printf("請按任意鍵繼續添加圖書 或者輸入q返回:");ch = getche(); if (ch == 'q' || ch == 'Q')break;}printf("\n");return head;
}void
print_book(Linkbook head)
{Linkbook L;L = head->next; printf("打印所有圖書信息:"); while (L != NULL) {printf("圖書名稱:%s\n", L->title);printf("圖書作者:%s\n", L->author);printf("圖書出版社:%s\n", L->publisher);printf("圖書出版時間:%s\n", L->pub_time);printf("圖書價格:%s\n", L->price);printf("圖書的ISBN:%s\n", L->ISBN);printf("圖書數量:%d\n\n\n", L->count);L = L->next;}printf("打印完成!!\n");
}//--------------------------------------------------------------int main(int argc, char const *argv[]) {
#ifndef _OJ_ //ONLINE JUDGEfreopen("input.txt", "r", stdin);//freopen("output.txt", "w", stdout);
#endifLinkbook Book = NULL; Linkstu Stu = NULL;Book = Creat_book();printf("booknext%s", Book->next->title);print_book(Book); return 0;
}
?
轉載于:https://www.cnblogs.com/airfand/p/5094996.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結