Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- int main()
- {
- FILE* data = fopen("data","rw");
- FILE* libbooks = fopen("books","r");
- int n;
- int o;
- char books [100];
- char bookname [30];
- char password [10];
- char username [10];
- char eof;
- int bob;
- char exiter;
- char password2 [10];
- char username2 [10];
- char eof2;
- char loginstatus [20];
- int userstatus = 0;
- int available;
- int copies;
- printf("WELCOME\n--------------------------\n\n");
- while (1)
- {
- printf("Please choose what to do: \n\n");
- printf("1- Login. \n 2- Scan for a book. \n 3- Request a book.\n 4- Exit.\n ");
- scanf("%d",&bob);
- switch (bob)
- {
- case 1:
- printf("Enter Username:\n");
- scanf("%s",username);
- printf("Enter Password:\n");
- scanf("%s",password);
- while (fscanf(data,"%c",&eof) != EOF)
- {
- fscanf(data,"%s %s",username2,password2);
- if( ( strcmp(password,password2) && strcmp(username,username2) ) == 0)
- {
- printf("login accepted!\n\n");
- userstatus = 1;
- break;
- }
- }
- if(userstatus == 0)
- printf("Authentication failed!\n\n");
- break;
- case 2:
- printf("Enter the title of the book you want:\n");
- scanf("%s",bookname);
- while(fscanf(libbooks,"%c",&eof2) != EOF)
- {
- fscanf(libbooks,"%s %d %d",books,&available,&copies);
- if (strcmp( bookname,books) == 0)
- {
- printf("Book found!\n");
- if(available ==0 && copies == 0)
- {
- printf("The book is not available right know.\n");
- }
- else if (available != 0 && copies != 0)
- {
- printf("The book is available,there are %d copies of the book.\n",copies);
- }
- }
- }
- break;
- case 4:
- return 0;
- break;
- case 5:
- if(userstatus == 1)
- printf("status: logged in\n\n");
- else
- printf("status: logged out\n\n");
- break;
- default:
- printf("Enter a number between the options listed above please.\n");
- }
- fclose(data);
- fclose(libbooks);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement