Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- int num = 0;
- void manage();
- void remove_member();
- void bookinsert();
- void search();
- void removebook();
- void sign_up();
- void bookdisplay();
- void sign_in();
- struct binfo
- {
- char book[100];
- char writer[100];
- struct binfo *next;
- }*head=NULL;
- void manage()
- {
- int n,i,a;
- while(1)
- {
- printf("\nPress : \n1 for sign in\n2 for Sign Up\n3 for remove member\n4 for book search\n5 for book insert\n6 for book remove\n7 for show booklist\n8 for exit\n");
- scanf("%d", &n);
- if(n==1){
- sign_in();
- }
- if(n==2)
- {
- sign_up();
- }
- else if(n==3)
- {
- remove_member();
- }
- else if(n==4)
- {
- search();
- }
- else if(n==5)
- {
- struct binfo *current, *new_node;
- new_node=(struct binfo*)malloc(sizeof(struct binfo));
- printf("Enter book name: ");
- scanf(" %[^\n]", new_node->book);
- printf("Enter writer name: ");
- scanf(" %[^\n]", new_node->writer);
- new_node->next=NULL;
- if (head==NULL)
- {
- num++;
- head=new_node;
- current = new_node;
- }
- else
- {
- num++;
- current->next = new_node;
- current = new_node;
- }
- }
- else if(n==6)
- {
- removebook();
- }
- else if(n==7)
- {
- bookdisplay();
- }
- else if(n==8)
- {
- break;
- }
- }
- }
- void search()
- {
- struct binfo *current;
- char n[100];
- int count = 0;
- while(1)
- {
- current = head;
- if(num>=1){
- printf("\nBook List : \n");
- while (current!=NULL)
- {
- count++;
- printf("%d. Book : %s\n Writer : %s\n\n",count, current->book, current->writer);
- current=current->next;
- }
- }
- else{
- printf("Booklist is empty\n");
- break;
- }
- printf("Enter book name : ");
- scanf(" %[^\n]", n);
- current = head;
- while(current != NULL)
- {
- if(strcmp(current->book, n) == 0)
- {
- printf("Book : %s\nWriter : %s\n", current->book, current->writer);
- break;
- }
- current = current->next;
- }
- break;
- }
- }
- void removebook()
- {
- struct binfo *current,*temp1,*temp2;
- int i,n,count = 0;
- while(1){
- if(num>=1){
- current = head;
- printf("\nBook List : \n");
- while (current!=NULL)
- {
- count++;
- printf("%d. Book : %s\n Writer : %s\n\n",count, current->book, current->writer);
- current=current->next;
- }
- }
- else{
- printf("Booklist is empty\n");
- break;
- }
- printf("Select a book : ");
- scanf("%d", &n);
- current = head;
- for(i=1;i<n;i++){
- current = current->next;
- }
- if(current == head)
- {
- num--;
- head = current->next;
- printf("Book removed successfully\n");
- break;
- }
- else if(current->next == NULL)
- {
- num--;
- current = head;
- for(i=1; i<=n-2; i++)
- {
- current = current->next;
- }
- current->next = NULL;
- printf("Book removed successfully\n");
- break;
- }
- else
- {
- num--;
- temp1 = current->next;
- current = head;
- for(i=1; i<=n-2; i++)
- {
- current = current->next;
- }
- current->next = temp1;
- printf("Book removed successfully\n");
- break;
- }
- }
- }
- void bookdisplay()
- {
- struct binfo *current;
- int count = 0;
- current=head;
- if(num>=1){
- printf("\nBook List : \n");
- while (current!=NULL)
- {
- count++;
- printf("%d. Book : %s\n Writer : %s\n\n",count, current->book, current->writer);
- current=current->next;
- }
- }
- else{
- printf("Booklist is empty\n");
- }
- }
- void sign_up()
- {
- FILE *fp, *f;
- char name[100], ch[100], ex[] = ".txt", c;
- char gmail[100];
- char pass[20];
- printf("Enter name : ");
- scanf(" %[^\n]", name);
- strcpy(ch, name);
- strcat(name, ex);
- fp = fopen(name, "r");
- if(fp == NULL)
- {
- fclose(fp);
- f = fopen(name, "w");
- fprintf(f, "Name : ");
- fprintf(f, ch);
- printf("Enter gmail : ");
- fprintf(f, "\n");
- getchar();
- fprintf(f, "Gmail : ");
- fprintf(f, gets(gmail));
- printf("Enter password : ");
- fprintf(f, "\n");
- fprintf(f,"Pass : ");
- fprintf(f, gets(pass));
- fclose(f);
- }
- else
- {
- fclose(fp);
- printf("You are already member\n");
- }
- }
- void remove_member()
- {
- FILE *fp, *f;
- char name[100],ex[] = ".txt";
- int x;
- printf("Enter name : ");
- scanf(" %[^\n]", name);
- strcat(name, ex);
- fp = fopen(name, "r");
- if(fp == NULL)
- {
- printf("Oops,, You are not member\n");
- }
- else
- {
- fclose(fp);
- x = remove(name);
- if(x==0) printf("Successfully removed\n");
- else printf("Failed to remove\n");
- }
- }
- void sign_in()
- {
- FILE *fp;
- char ch[100], ex[] = ".txt",pass[50];
- printf("Enter Name : ");
- scanf(" %[^\n]", ch);
- strcat(ch,ex);
- fp = fopen(ch, "r");
- if(fp == NULL){
- fclose(fp);
- printf("You are not member\nPlease sign up first\n");
- return;
- }
- else{
- fclose(fp);
- printf("Enter password : ");
- scanf(" %[^\n]", pass);
- printf("Sign in successful\n");
- }
- }
- int main()
- {
- printf(" --------------------->>>> Welcome to our Library management system <<<<---------------------------\n Team : Casual Programmers\n");
- manage();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement