#include<stdio.h>
#define MAX 36
void resetAllBook(bool bookDtatus[MAX]);
void showALLbookStatus(bool bookStatus[MAX]); // false = free , true = Booked
bool returnBook(bool bookDtatus[MAX]);
bool borrowBook(bool bookStatus[MAX]);
int menu();
char line[500];
char name[100];
struct active_users{
int id;
char name[50];
};
main(){
bool bookStatus[MAX];
resetAllBook(bookStatus);
int choice;
struct active_users act[1];
int i;
printf("=================: LoGIN :=================\n");
printf("Enter Username : "); scanf("%s" ,&act.name);
printf("Enter Id : "); scanf("%d",&act.id);
printf("\n======: WELCOME TO WORLD LIBRARY :======\n");
printf("Hello! : %s \n\n",act.name);
FILE *inputF;
inputF = fopen("Listbooks.txt", "r");
if(inputF == NULL){
printf("Cannot open this file\n");
return 0;
}
while (fgets(line, 500, inputF) !=NULL){
printf("%s",line);
}
fclose(inputF);
do{
choice = menu();
switch(choice){
case 0: //Exit
printf("!!! Bye Bye !!!");
break;
case 1: //Borrow
printf("\n=================: Borrow a Book :=================\n");
if(borrowBook(bookStatus)){
printf("\nbookStatus : borrow success\n");
}else{
printf("\nbookStatus : fail to borrow\n");
}
printf("\n===================================================\n");
break;
case 2: //return
printf("\n=================: return a Book :=================\n");
if(returnBook(bookStatus)){
printf("\nbookStatus : return success\n");
}else{
printf("\nbookStatus : fail to return\n");
}
printf("\n===================================================\n");
break;
case 3: //Show status
printf("\n=================: Book Status :=================\n\n");
showALLbookStatus(bookStatus);
break;
default:
break;
}
}while(choice!=0);
return 0 ;
}
bool returnBook(bool bookStatus[MAX]){
int bookNumber;
printf("\nEnter your number of book for Returning : Number ");
scanf("%d",&bookNumber);
if(bookNumber>=1 && bookNumber<=MAX && !bookStatus[bookNumber]){
bookStatus[bookNumber] = false;
return true;
}
return false;
}
bool borrowBook(bool bookStatus[MAX]){
int bookNumber;
printf("\nEnter your number of book for borrowing : Number ");
scanf("%d",&bookNumber);
if(bookNumber>=1 && bookNumber<=MAX && !bookStatus[bookNumber]){
bookStatus[bookNumber] = false;
return true;
}
return false;
}
void resetALLBook(bool bookStatus[MAX]){
for(int i=1;i<MAX;i++){
bookStatus = false ;
}
}
void showALLbook(bool bookStatus[MAX]){
for(int i=1;i<MAX;i++){
if(!bookStatus==true){
printf(" Book Number. %d Status = Free\n ",i);
}else{
printf(" Book Number. %d Status = BOOKED\n ",i);
}
}
}
int menu(){
int choice;
printf("\n\nWant to do any choice?\n");
printf("1. borrow book\n");
printf("2. return book\n");
printf("3. book Status\n");
printf("0. exit\n");
printf("\nEnter Choice : ");
scanf("%d",&choice);
return choice;
}
ช่วยแก้ไขโค้ดโปรแกรมห้องสมุดอันนี้หน่อยได้ไหมคะ เขียนไปแล้วมันขึ้น [error] Id returned 1 exit status แก้ยังไงหรอคะTT
#define MAX 36
void resetAllBook(bool bookDtatus[MAX]);
void showALLbookStatus(bool bookStatus[MAX]); // false = free , true = Booked
bool returnBook(bool bookDtatus[MAX]);
bool borrowBook(bool bookStatus[MAX]);
int menu();
char line[500];
char name[100];
struct active_users{
int id;
char name[50];
};
main(){
bool bookStatus[MAX];
resetAllBook(bookStatus);
int choice;
struct active_users act[1];
int i;
printf("=================: LoGIN :=================\n");
printf("Enter Username : "); scanf("%s" ,&act.name);
printf("Enter Id : "); scanf("%d",&act.id);
printf("\n======: WELCOME TO WORLD LIBRARY :======\n");
printf("Hello! : %s \n\n",act.name);
FILE *inputF;
inputF = fopen("Listbooks.txt", "r");
if(inputF == NULL){
printf("Cannot open this file\n");
return 0;
}
while (fgets(line, 500, inputF) !=NULL){
printf("%s",line);
}
fclose(inputF);
do{
choice = menu();
switch(choice){
case 0: //Exit
printf("!!! Bye Bye !!!");
break;
case 1: //Borrow
printf("\n=================: Borrow a Book :=================\n");
if(borrowBook(bookStatus)){
printf("\nbookStatus : borrow success\n");
}else{
printf("\nbookStatus : fail to borrow\n");
}
printf("\n===================================================\n");
break;
case 2: //return
printf("\n=================: return a Book :=================\n");
if(returnBook(bookStatus)){
printf("\nbookStatus : return success\n");
}else{
printf("\nbookStatus : fail to return\n");
}
printf("\n===================================================\n");
break;
case 3: //Show status
printf("\n=================: Book Status :=================\n\n");
showALLbookStatus(bookStatus);
break;
default:
break;
}
}while(choice!=0);
return 0 ;
}
bool returnBook(bool bookStatus[MAX]){
int bookNumber;
printf("\nEnter your number of book for Returning : Number ");
scanf("%d",&bookNumber);
if(bookNumber>=1 && bookNumber<=MAX && !bookStatus[bookNumber]){
bookStatus[bookNumber] = false;
return true;
}
return false;
}
bool borrowBook(bool bookStatus[MAX]){
int bookNumber;
printf("\nEnter your number of book for borrowing : Number ");
scanf("%d",&bookNumber);
if(bookNumber>=1 && bookNumber<=MAX && !bookStatus[bookNumber]){
bookStatus[bookNumber] = false;
return true;
}
return false;
}
void resetALLBook(bool bookStatus[MAX]){
for(int i=1;i<MAX;i++){
bookStatus = false ;
}
}
void showALLbook(bool bookStatus[MAX]){
for(int i=1;i<MAX;i++){
if(!bookStatus==true){
printf(" Book Number. %d Status = Free\n ",i);
}else{
printf(" Book Number. %d Status = BOOKED\n ",i);
}
}
}
int menu(){
int choice;
printf("\n\nWant to do any choice?\n");
printf("1. borrow book\n");
printf("2. return book\n");
printf("3. book Status\n");
printf("0. exit\n");
printf("\nEnter Choice : ");
scanf("%d",&choice);
return choice;
}