//help me i dont know what wrong with list function
#include <stdio.h>
#define MAX 10
struct book{
char title[81];
char author[71];
char category[31];
};
int main()
{
struct book library[MAX];
int menu(void);
struct book add(void);
int list(struct book,int);
int choice, count = 0;
do
{
choice = menu();
switch( choice )
{
case 0:
puts("End of my act! :-)");
break;
case 1:
if (count < MAX )
{
library[count] = add();
count++;
}
else
puts("Library is reached maximum value");
break;
case 2:
list(library[count],count);
break;
default:
puts("Wrong selection. Try again");
}
}while(choice != 0 );
return 0;
}//end of main
//this function show the main menu read the user selection and return the user selection to the caller
int menu(void)
{
int choice;
puts("\n<<Super duper menu>>");
puts("\t0:Exit");
puts("\t1:Add a book");
puts("\t2:List all books");
printf("Enter your selection");
scanf("%d",&choice);
return choice;
}
struct book add(void)
{
struct book temp;
fflush(stdin);
puts("\n <<ADD MORE>>");
printf("Title?");
gets(temp.title);
printf("Author?");
gets(temp.author);
printf("Category");
return temp;
}
void list(struct book *sp,int size)
{
int i;
puts("\n");
puts("<<BOOKS LIST>>");
for(i = 0; i < size;++i,++sp)
printf("%d by %s - - - %s\n", i + 1, sp ->title, sp ->author, sp ->category);
return;
}