C PROGRAM FOR LIBRARY OPERATION
A library in C is a group of functions and declarations, exposed for use by
other programs. The library therefore consists of an interface expressed
in a .h file (named the "header") and an implementation expressed in a .c file.
This .c file might be precompiled or otherwise inaccessible, or it might be
available to the programmer. (Note: Libraries may call functions in other
libraries such as the Standard C or math libraries to do various tasks.)
The format of a library varies with the operating system and compiler one is using. For example, in the Unix and Linux operating systems, a library
consists of one or more object files, which consist of object code that is
usually the output of a compiler (if the source language is C or something
similar) or an assembler (if the source language is assembly language). These
object files are then turned into a library in the form of an archive by the ar
archiver (a program that takes files and stores them in a bigger file without
regard to compression). The filename for the library usually starts with "lib"
and ends with ".a"; e.g. the libc.a file contains the Standard C library and the
"libm.a" the mathematics routines, which the linker would then link in. Other
operating systems such as Microsoft Windows use a ".lib" extension for libraries
and an ".obj" extension for object files.
CODE:
#include<stdio.h>
#include<conio.h>
int i=0;
void add();
void search();
void sort();
void sorta();
struct book
{
char bookname[50];
char author[50];
double price;
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");
printf("\nBOOK NAME: %s",book[i].bookname);
printf("\nAUTHOR : %s",book[i].author);
printf("\nPRICE : %d",book[i].price);
printf("\nNO OF COPIES: %d",book[i].nocopy);
i++;
getch();
}
void search()
{
int f=0,y,j,x;
char bookn[50],authorname[50];
printf("\n Enter the Book Name: ");
fflush(stdin);
gets(bookn);
printf("\n Enter the Author Name: ");
fflush(stdin);
gets(authorname);
printf("\nThe Given Search");
printf("\nThe Book Name is: %s",bookn);
printf("\nThe Author Name is : %s",authorname);
for(j=0;j<i;j++)
{
x= strcmp(book[j].bookname,bookn);
y=strcmp(book[j].author,authorname);
if(x==0&&y==0)
{
printf("\nBOOK IS FOUND");
getch();
f=1;
}
}
if(f==0)
{
printf("\nBOOK NOT FOUND");
getch();
}
getch();
}
void sort()
{
int j,k,x;
char t[50];
for(j=0;j<i;j++)
{
for(k=0;k<j;k++)
{
x = (strcmp(book[k].bookname,book[k+1].bookname));
if(x>0)
{
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();
}
0 comments:
Post a Comment