C Programs
C Programs
c
cc
!
"
#$
%
&'(
&'&)'*+'(
#$(
, #- . "/-$(
#-0
-'1&$(
&+#&2$34(
33 , #-0-'#&$$(
&)+&2&(
+(
*+(
#+)(5#$cc(+6)$
%
+ #&)2#7$$3#2#7$$(
* + *6(
8
, #-9 :; 0-'*$(
#$(
8
c
c
cc
!
"
#$
%
&'(
&'&)'*+'(
#$(
, #- . "/-$(
#-0
-'1&$(
&+#&2$34(
33 , #-0-'#&$$(
&)+&2&(
+(
*+(
#+)(5#$cc(+6)$
%
+ #&)2#7$$3#2#7$$(
* + *6(
8
, #-9 :; 0-'*$(
#$(
8
;#$
%, #-9 9 < ," 59 -$(
, #- : "/-$(
#-0
-'1$(
8
5+#$(
, #-0
-'5$(
#$(
8
# &$
%
#&++$
%
#$(
8
%
##&$2##&7$$$(
8
8
8
%
#5#&7$6#5#&7)$$$(
8
8
int nocopy;
}book[50];
void main()
{
int ch;
while(1)
{
clrscr();
printf("********************");
printf("\nLIBRARY MANAGEMENT");
printf("\n******************");
printf("\n1-ADD TO LIBRARY");
printf("\n2-SEARCH A BOOK");
printf("\n3-SORT BY BOOK NAME");
printf("\n4-SORT BY AUTHOR NAME");
printf("\n5-EXIT");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: add();
break;
case 2: search();
break;
case 3: sort();
break;
case 4: sorta();
break;
case 5: exit(0);
default: puts("Please enter 1-5 only");
getch();
}
}
}
void add()
{
printf("\n\nADD TO LIBRARY");
printf("\nEnter the Bookname: ");
fflush(stdin);
gets(book[i].bookname);
printf("\nEnter the Author name: ");
fflush(stdin);
gets(book[i].author);
printf("\nEnter the Price of the Book: ");
scanf("%ld",&book[i].price);
printf("\nEnter no of copies : ");
scanf("%d",&book[i].nocopy);
printf("STORED");
{
strcpy(t,book[k].bookname);
strcpy(book[k].bookname ,book[k+1].bookname);
strcpy(book[k+1].bookname, t);
}
}
}
printf("\nSORTED BY BOOK NAME");
for(j=0;j<i;j++)
{
printf("\nThe BookName is:%s - %s",book[j].bookname,book[j].author);
}
getch();
}
void sorta()
{
int j,k,x;
char t[50];
for(j=0;j<i;j++)
{
for(k=0;k<j;k++)
{
x = (strcmp(book[k].author,book[k+1].author));
if(x>0)
{
strcpy(t,book[k].author);
strcpy(book[k].author ,book[k+1].author);
strcpy(book[k+1].author, t);
}
}
}
printf("\nSORTED BY AUTHOR NAME");
for(j=0;j<i;j++)
{
printf("\nThe AUTHOR NAME is:%s - %s",book[j].author,book[j].bookname);
}
getch();
}
{
if(j%i==0)
{
a=1;
goto x;
}
}
if((a==0)&&(j!=1))
{
printf("\n%d",j);
}
x:
a=0;
}
getch();
}