hello,
it is a book database i have made 3 functions out of 5 plz help me
these functions are not giving right output .plz plz plz help.
i wil be highly thankful to him/her.plz
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct data
{
int book_id;
char authername[89];
char bookname[80];
float price;
};
struct data book[40];
void menu(void);
void add(void);
void sort(void);
void _display(void);
//void bookdetails(void);
int new;
main()
{
char ch;
while(1)
{
clrscr();
menu();
printf("\n enter choice\n");
ch=getche();
switch(ch)
{
case'1':
add();
break;
case'2':
sort();
break;
case'3':
_display();
break;
/* case'4':
bookdetails();
break;*/
case'5':
exit(0);
break;
//default:
// printf("\n enter a valid choice\n");
}
}
}
void menu(void)
{
clrscr();
printf("\n book database");
printf("\n 1.add abook");
printf("\n 2.sort");
printf("\n 3.price");
printf("\n 4.bookdetails");
printf("\n 5.exit");
}
void add(void)
{
char x[9];
clrscr();
if(new<40)
{
printf("\nenter bookid:");
gets(x);
book[new].book_id=atoi(x);
printf("\nenter book price:");
gets(x);
book[new].price=atof(x);
printf("enter book author name");
gets(book[new].authername);
printf("enter book name");
gets(book[new].bookname);
new++;
printf("book entere\n");
getch();
}
else
printf("not enough memory");
}
void sort(void)
{ int i,o;
float temp=0;
// struct data temp;
for(o=0;o<new-1;o++)
{
for(i=o+1;i<new;i++)
{
if(book[o].price>book[i].price)
{
temp=book[o].price;
book[o].price=book[i].price;
book[i].price=temp;
}
}
}
}
void _display(void)
{
int x=0;
char ch;
printf("\n\n\n displaying books records");
do
{
if(x<new)
{
printf("\n record # %d\n",x+1);
printf("\n book name %s",book[x].bookname);
printf("\n author name: %s",book[x].authername);
printf("\n book id %d",book[x].book_id);
printf("\n book price %f ",book[x].price);
x++;
printf("press enter to see the next record or exit by pressing esc key");
ch=getche();
if(ch==27)
break;
}
else
printf("\n \n no more record");
getch();
break;
}while(ch!='27');
}