#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define CUSHION 50 /* for array sizes*/
#define RECLMT 20 /* amount of records */
struct book
{
char title[CUSHION];
char firstname[CUSHION];
char lastname[CUSHION];
char isbn[13]; /*ISBN Number consists of 13 numbers*/
char publisher[CUSHION];
char dop[4]; /*only the year needed*/
};
struct book Book[RECLMT]; /*20 records*/
int populate(void);
void welcome_menu(void); /* Options menu */
int choice(char);
/* MAIN STARTS HERE */
int main()
{
welcome_menu();
return 0;
}
/* MAIN ENDS HERE */
/* start menu */
void welcome_menu(void)
{
char p;
printf(" ******************************************\n"); printf(" * Welcome to the Mile End Library System *\n"); printf(" ******************************************\n\n"); printf("Type the number corresponding\n to your desired action:\n\n"); printf("1. ADD A BOOK\n2. UPDATE AN EXISTING ENTRY\n3. BOOK SEARCH\n4. PRINT ALL FILE RECORDS\n"); printf("\n5. (FOR ADMIN USE ONLY) POPULATE FILE\n\n");/*options keys*/
choice(p);
}
int populate(void)
{
printf("All entries will be saved in the file, books.dat.\n\n" );
int c=0, x=0;
/* struct book Book[RECLMT]; */
char s;
for(;c<=RECLMT;c++){
while ( ( s
= getchar() ) !='\n' ){
Book[c].title[ x++ ] = s;
}
Book[c].title[x]='\0';
printf("Author's first name?\t");
while ( ( s
= getchar() ) !='\n' ){
Book[c].firstname[ x++ ] = s;
}
Book[c].firstname[x]='\0';
printf("Author's last name?\t");
while ( ( s
= getchar() ) !='\n' ){
Book[c].lastname[ x++ ] = s;
}
Book[c].lastname[x]='\0';
while ( ( s
= getchar() ) !='\n' ){
Book[c].isbn[ x++ ] = s;
}
Book[c].isbn[x]='\0';
printf("Year of publication?\t");
while ( ( s
= getchar() ) !='\n' ){
Book[c].dop[ x++ ] = s;
}
Book[c].dop[x]='\0';
}
struct book *books;
*books = Book ;
FILE *bibPtr; /* file handle */
bibPtr
=fopen( "books.dat","w" ); if( bibPtr == NULL )
{ printf( "No file found.\n" );} else
{
fwrite(books
,sizeof(*Book
),RECLMT
,bibPtr
); }
}
int choice(char p)
{
switch(p)
{
case '1':
break;
case '2':
break;
case '3':
break;
case '4':
break;
case '5':
populate();
break;
default:
welcome_menu;
}
}
/* A function to remedy the repeated requests in populate() */
/*
*entry(char[],int)
{
while ( ( s = getchar() ) !='\n' ){
Book[c].title[ x++ ] = s;
}
Book[c].title[x]='\0';
}
*/
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPGN0eXBlLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCiNkZWZpbmUgQ1VTSElPTiA1MCAvKiBmb3IgYXJyYXkgc2l6ZXMqLwojZGVmaW5lIFJFQ0xNVCAyMCAvKiBhbW91bnQgb2YgcmVjb3JkcyAqLwoKc3RydWN0IGJvb2sKewogICAgY2hhciB0aXRsZVtDVVNISU9OXTsKICAgIGNoYXIgZmlyc3RuYW1lW0NVU0hJT05dOwogICAgY2hhciBsYXN0bmFtZVtDVVNISU9OXTsKICAgIGNoYXIgaXNiblsxM107IC8qSVNCTiBOdW1iZXIgY29uc2lzdHMgb2YgMTMgbnVtYmVycyovCiAgICBjaGFyIHB1Ymxpc2hlcltDVVNISU9OXTsKICAgIGNoYXIgZG9wWzRdOyAvKm9ubHkgdGhlIHllYXIgbmVlZGVkKi8KfTsKCnN0cnVjdCBib29rIEJvb2tbUkVDTE1UXTsgLyoyMCByZWNvcmRzKi8KCmludCBwb3B1bGF0ZSh2b2lkKTsKCnZvaWQgd2VsY29tZV9tZW51KHZvaWQpOyAvKiBPcHRpb25zIG1lbnUgKi8KCmludCBjaG9pY2UoY2hhcik7CgovKiBNQUlOIFNUQVJUUyBIRVJFICovCmludCBtYWluKCkKewogICAgd2VsY29tZV9tZW51KCk7CgkKCXJldHVybiAwOwp9CgovKiBNQUlOIEVORFMgSEVSRSAqLwoKLyogc3RhcnQgbWVudSAqLwp2b2lkIHdlbGNvbWVfbWVudSh2b2lkKQp7CgljaGFyIHA7CiAgICBwcm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