Message
Message
h>
#include <stdlib.h>
#define max 100
int actualsize = 0;
int actualsize1 = 0;
int actualsize2 = 0;
//int books_borrowed();
//int new_book();
//int search_book();
//int searchb_code ();
//int display_popular_books();
//int exitp();
//this structure of the file holds the members who borrowed books
struct returns
{
char membername[50];
int bookcode;
char booktitle[50];
char author[50];
char borrowed[20];
char returns[20];
}r[100];
// password function checks for a passcode and returns 1 for correct and 0 for
wrong
int password()
{
int p=0, code= 1111; int attempts=0;
while(attempts<3){
printf("\nPlease enter the correct 4-digit passcode:");
scanf("%d",&p);
if (p == code)
{
return 1;
}
else
{
printf("\nError!Incorrect passcode.Please try again\n");
attempts++;
}
}
//this function reads the data from the input file into the array of structures
with the members of the library
int readdata(){
FILE*in=fopen("inputmembers.txt","r");
int c=0;
if (in == NULL)
printf("\nThe file is empty");
else
{
while (!feof(in))
{
fscanf(in,"%s",&m[c].name);
printf("Name: %s",m[c].name);
fscanf(in,"%d",&m[c].age);
printf(" Age: %d",m[c].age);
fscanf(in," %c",&m[c].gender);
printf(" Gender: %c",m[c].gender);
fscanf(in,"%d",&m[c].contact);
printf(" Contact: %d",m[c].contact);
fscanf(in,"%s",m[c].email);
printf(" Email: %s \n\n",m[c].email);
c++;
}
printf("/nThe data from the file was read properly.");
actualsize = c;
}
//this function reads the data from the input file into the array of
structures with the books in the library
FILE*in2=fopen("inputbooks1.txt","r");
int i=0;
if (in2 == NULL)
printf("\nThe file is empty");
else
{
while (!feof(in2))
{
fscanf(in2,"%d",&b[i].bookcode);
printf("\nBook Code: %d \n",b[i].bookcode);
fscanf(in2,"%s ",&b[i].title);
printf("Title: %s \n",b[i].title);
fscanf(in2,"%s ",&b[i].author);
printf("Author: %s \n",b[i].author);
fscanf(in2,"%s ",&b[i].category);
printf("Category: %s \n",b[i].category);
i++;
printf("Counter: %d\n\n",i);
}
printf("/nThe data from the file was read properly.");
actualsize1 = i;
}
//this function reads the data from the input file into the array of
structures with the members of the library who borrowed books
FILE*in3=fopen("inputreturns.txt","r");
int n=0;
if (in3 == NULL)
printf("\nThe file is empty");
else
{
while (!feof(in3))
{
fscanf(in3,"%s",&r[n].membername);
printf("\n\nMember Name: %s \n",r[n].membername);
fscanf(in3,"%d",&r[n].bookcode);
printf("Book Code: %d \n",r[n].bookcode);
fscanf(in3,"%s",&r[n].booktitle);
printf("Book Title: %s \n",r[n].booktitle);
fscanf(in3,"%s",&r[n].author);
printf("Book Title: %s \n",r[n].author);
fscanf(in3,"%s",&r[n].borrowed);
printf("Date Borrowed: %s \n",r[n].borrowed);
fscanf(in3,"%s",&r[n].returns);
printf("Date to be Returned: %s \n\n",&r[n].returns);
n++;
printf("\nCounter: %d\n\n",n);
}
printf("/nThe data from the file was read properly.");
actualsize2 = n;
}
}
//this function displays the options to the user and returns an option
int menu()
{
int choice=-1;
printf("Please choose from the following menu options\n\n");
printf("1: Display all data\n");
printf("2: Add a member\n");
printf("3: Search for a member\n");
printf("4 :Update a member's contact information'\n");
printf("5 :Search for a book\n");
printf("6: Display books borrowed\n");
printf("0 :Exit\n");
}
else
return choice;
printf("Name: ");
scanf(" %s", m[actualsize].name);
printf("Age: ");
scanf(" %d", &m[actualsize].age);
printf("Gender (M/F): ");
scanf(" %c", &m[actualsize].gender);
printf("Contact: ");
scanf(" %d", &m[actualsize].contact);
printf("Email: ");
scanf(" %s", m[actualsize].email);
actualsize++;
}
printf("\nPlease enter the contact update you would like to make: \n");
scanf("%d",&contact);
index=search_member(contact);
printf("\nPlease enter the member name:\n");
scanf("%s",&m[index].name);
//print_info(index);
//print out full member updated info to the screen after given an index
void print_info(int index)
{
if (index == -1)
{
printf("Member does not exist");
}
else
{
printf("Name: %s",m[index].name);
printf("Age: %d",m[index].age);
printf("Gender: %c",m[index].gender);
printf("Contact: %d",m[index].contact);
printf("Email: %s \n",m[index].email);
}
}
int books_borrowed()
{
int n=0;
{
if (actualsize2==0){
printf("\n No books have been been borrowed yet\n");
return;
}
}
FILE*out=fopen("borrowed_books","w");
for(n=0;n<actualsize;n++){
printf("Member Name:%s\n",r[n].membername);
printf("Book Code:%d\n",r[n].bookcode);
printf("Book title:%s\n",r[n].booktitle);
printf("Author:%s\n",r[n].author);
printf("Date borrowed:%s\n",r[n].borrowed);
printf("Return Date:%s\n",r[n].returns);
fprintf(out,"Member Name:%s\n",r[n].membername);
fprintf(out,"Book code:%d\n",r[n].bookcode);
fprintf(out,"Book title:%d\n",r[n].booktitle);
fprintf(out,"Author:%s\n",r[n].author);
fprintf(out,"Date borrowed:%s\n",r[n].borrowed);
fprintf(out,"Return Date:%s\n",r[n].returns);
}
}
printf("Bookcode: ");
scanf("%d", b[actualsize].bookcode);
printf("Title: ");
scanf("%s", b[actualsize].title);
printf("Author: ");
scanf("%s", b[actualsize].author);
printf("Category: ");
scanf("%s ", b[actualsize].category);
printf("Genre: ");
scanf("%s", b[actualsize].genre);
actualsize++;
int g=0;
for (g=0;g<actualsize1;g++)
{
printf("this is searching");
if (searchb == b[g].bookcode)
{
printf("Book: %s",b[g].title);
return g;
}
}
return -1;
int exitp()
{
printf("Exiting the system... Goodbye!\n");
}
welcome();
int p = password();
int code=1111;
while (p==0)
{
printf("passcode incorrect, please enter correct code: \n");
p=password();
}
if (choice == 2)
{
printf("Option two was chosen\n");
add_member();
}
if (choice == 3)
{
printf("\nOption 3 was choosen\n");
if (loc == -1)
{
printf("\nNobody was found\n\n\n");
}
}
if (choice == 4)
{
printf("Option 4 was choosen\n");
update_member();
}
if (choice == 5)
{
if(loc == -1);
{
printf ("\n Book was not found\n\n\n");
}
if (choice == 6)
{
books_borrowed();
printf("Option 6 was choosen\n");
}
choice = menu();
}