Mahfuz123

Shakil's Project

Dec 2nd, 2019
220
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. int num = 0;
  6.  
  7. void manage();
  8. void remove_member();
  9. void bookinsert();
  10. void search();
  11. void removebook();
  12. void sign_up();
  13. void bookdisplay();
  14. void sign_in();
  15.  
  16. struct binfo
  17. {
  18. char book[100];
  19. char writer[100];
  20. struct binfo *next;
  21.  
  22. }*head=NULL;
  23.  
  24. void manage()
  25. {
  26. int n,i,a;
  27.  
  28. while(1)
  29. {
  30. 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");
  31. scanf("%d", &n);
  32.  
  33. if(n==1){
  34. sign_in();
  35. }
  36.  
  37. if(n==2)
  38. {
  39. sign_up();
  40. }
  41. else if(n==3)
  42. {
  43. remove_member();
  44. }
  45. else if(n==4)
  46. {
  47. search();
  48. }
  49. else if(n==5)
  50. {
  51. struct binfo *current, *new_node;
  52.  
  53. new_node=(struct binfo*)malloc(sizeof(struct binfo));
  54.  
  55. printf("Enter book name: ");
  56. scanf(" %[^\n]", new_node->book);
  57. printf("Enter writer name: ");
  58. scanf(" %[^\n]", new_node->writer);
  59.  
  60. new_node->next=NULL;
  61.  
  62. if (head==NULL)
  63. {
  64. num++;
  65. head=new_node;
  66. current = new_node;
  67. }
  68. else
  69. {
  70. num++;
  71. current->next = new_node;
  72. current = new_node;
  73. }
  74. }
  75. else if(n==6)
  76. {
  77. removebook();
  78. }
  79. else if(n==7)
  80. {
  81. bookdisplay();
  82. }
  83. else if(n==8)
  84. {
  85. break;
  86. }
  87. }
  88. }
  89.  
  90.  
  91. void search()
  92. {
  93. struct binfo *current;
  94. char n[100];
  95. int count = 0;
  96.  
  97. while(1)
  98. {
  99. current = head;
  100. if(num>=1){
  101. printf("\nBook List : \n");
  102. while (current!=NULL)
  103. {
  104. count++;
  105. printf("%d. Book : %s\n Writer : %s\n\n",count, current->book, current->writer);
  106. current=current->next;
  107. }
  108. }
  109. else{
  110. printf("Booklist is empty\n");
  111. break;
  112. }
  113. printf("Enter book name : ");
  114. scanf(" %[^\n]", n);
  115.  
  116. current = head;
  117.  
  118. while(current != NULL)
  119. {
  120. if(strcmp(current->book, n) == 0)
  121. {
  122. printf("Book : %s\nWriter : %s\n", current->book, current->writer);
  123. break;
  124. }
  125. current = current->next;
  126. }
  127. break;
  128. }
  129. }
  130.  
  131.  
  132. void removebook()
  133. {
  134. struct binfo *current,*temp1,*temp2;
  135. int i,n,count = 0;
  136.  
  137. while(1){
  138. if(num>=1){
  139. current = head;
  140. printf("\nBook List : \n");
  141. while (current!=NULL)
  142. {
  143. count++;
  144. printf("%d. Book : %s\n Writer : %s\n\n",count, current->book, current->writer);
  145. current=current->next;
  146. }
  147. }
  148. else{
  149. printf("Booklist is empty\n");
  150. break;
  151. }
  152. printf("Select a book : ");
  153. scanf("%d", &n);
  154.  
  155. current = head;
  156.  
  157. for(i=1;i<n;i++){
  158. current = current->next;
  159. }
  160.  
  161. if(current == head)
  162. {
  163. num--;
  164. head = current->next;
  165. printf("Book removed successfully\n");
  166. break;
  167. }
  168. else if(current->next == NULL)
  169. {
  170. num--;
  171. current = head;
  172. for(i=1; i<=n-2; i++)
  173. {
  174. current = current->next;
  175. }
  176. current->next = NULL;
  177. printf("Book removed successfully\n");
  178. break;
  179. }
  180. else
  181. {
  182. num--;
  183. temp1 = current->next;
  184. current = head;
  185.  
  186. for(i=1; i<=n-2; i++)
  187. {
  188. current = current->next;
  189. }
  190.  
  191. current->next = temp1;
  192. printf("Book removed successfully\n");
  193. break;
  194. }
  195. }
  196.  
  197. }
  198.  
  199. void bookdisplay()
  200. {
  201. struct binfo *current;
  202. int count = 0;
  203. current=head;
  204.  
  205. if(num>=1){
  206. printf("\nBook List : \n");
  207. while (current!=NULL)
  208. {
  209. count++;
  210. printf("%d. Book : %s\n Writer : %s\n\n",count, current->book, current->writer);
  211. current=current->next;
  212. }
  213. }
  214. else{
  215. printf("Booklist is empty\n");
  216. }
  217. }
  218.  
  219. void sign_up()
  220. {
  221. FILE *fp, *f;
  222. char name[100], ch[100], ex[] = ".txt", c;
  223. char gmail[100];
  224. char pass[20];
  225.  
  226. printf("Enter name : ");
  227. scanf(" %[^\n]", name);
  228. strcpy(ch, name);
  229. strcat(name, ex);
  230.  
  231. fp = fopen(name, "r");
  232. if(fp == NULL)
  233. {
  234. fclose(fp);
  235. f = fopen(name, "w");
  236. fprintf(f, "Name : ");
  237. fprintf(f, ch);
  238.  
  239. printf("Enter gmail : ");
  240. fprintf(f, "\n");
  241. getchar();
  242. fprintf(f, "Gmail : ");
  243. fprintf(f, gets(gmail));
  244.  
  245. printf("Enter password : ");
  246. fprintf(f, "\n");
  247. fprintf(f,"Pass : ");
  248. fprintf(f, gets(pass));
  249.  
  250. fclose(f);
  251.  
  252. }
  253. else
  254. {
  255. fclose(fp);
  256. printf("You are already member\n");
  257. }
  258. }
  259.  
  260. void remove_member()
  261. {
  262. FILE *fp, *f;
  263. char name[100],ex[] = ".txt";
  264. int x;
  265.  
  266. printf("Enter name : ");
  267. scanf(" %[^\n]", name);
  268. strcat(name, ex);
  269.  
  270. fp = fopen(name, "r");
  271.  
  272. if(fp == NULL)
  273. {
  274. printf("Oops,, You are not member\n");
  275. }
  276. else
  277. {
  278. fclose(fp);
  279. x = remove(name);
  280. if(x==0) printf("Successfully removed\n");
  281. else printf("Failed to remove\n");
  282. }
  283. }
  284.  
  285. void sign_in()
  286. {
  287. FILE *fp;
  288. char ch[100], ex[] = ".txt",pass[50];
  289.  
  290. printf("Enter Name : ");
  291. scanf(" %[^\n]", ch);
  292. strcat(ch,ex);
  293.  
  294. fp = fopen(ch, "r");
  295.  
  296. if(fp == NULL){
  297. fclose(fp);
  298. printf("You are not member\nPlease sign up first\n");
  299. return;
  300. }
  301. else{
  302. fclose(fp);
  303. printf("Enter password : ");
  304. scanf(" %[^\n]", pass);
  305. printf("Sign in successful\n");
  306. }
  307. }
  308.  
  309. int main()
  310. {
  311. printf(" --------------------->>>> Welcome to our Library management system <<<<---------------------------\n Team : Casual Programmers\n");
  312. manage();
  313.  
  314. return 0;
  315. }
RAW Paste Data