Advertisement
Guest User

Personal Diary Management System

a guest
Jul 23rd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.69 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. #include<stdlib.h>
  4.  
  5. #include<conio.h>
  6.  
  7. #include<string.h>
  8.  
  9.  
  10. void addrecord();
  11.  
  12. void viewrecord();
  13.  
  14. void editrecord();
  15.  
  16.  
  17. void deleterecord();
  18.  
  19.  
  20. struct record
  21.  
  22. {
  23.  
  24. char time[6];
  25.  
  26. char name[30];
  27.  
  28. char note[500];
  29.  
  30. } ;
  31.  
  32.  
  33. int main()
  34.  
  35. {
  36.  
  37. int ch;
  38.  
  39. printf("\n\n\t**********************\n");
  40.  
  41. printf("\t*PERSONAL DIARY*\n");
  42.  
  43. printf("\t**************************");
  44.  
  45.  
  46. while(1)
  47.  
  48.  
  49. {
  50.  
  51. printf("\n\n\t\tMAIN MENU:");
  52.  
  53. printf("\n\n\tADD RECORD\t[1]");
  54.  
  55. printf("\n\tVIEW RECORD\t[2]");
  56.  
  57. printf("\n\tEDIT RECORD\t[3]");
  58.  
  59. printf("\n\tDELETE RECORD\t[4]");
  60.  
  61. printf("\n\tEXIT\t\t[5]");
  62.  
  63. printf("\n\n\tENTER YOUR CHOICE:");
  64.  
  65. scanf("%d",&ch);
  66.  
  67.  
  68. switch(ch)
  69.  
  70. {
  71.  
  72. case 1:
  73.  
  74. addrecord();
  75.  
  76. break;
  77.  
  78.  
  79. case 2:
  80.  
  81. viewrecord();
  82.  
  83. break;
  84.  
  85.  
  86. case 3:
  87.  
  88. editrecord();
  89.  
  90. break;
  91.  
  92.  
  93. case 4:
  94.  
  95. deleterecord();
  96.  
  97. break;
  98.  
  99.  
  100. case 5:
  101.  
  102. printf("\n\n\t\tTHANK YOU FOR USING THE SOFTWARE BY:\n\n\tShahriar \n\n\tArup\n\n\tProtap\n\n\tShuvo");
  103.  
  104. getch();
  105.  
  106. exit(0);
  107.  
  108. }
  109.  
  110. system("cls");
  111.  
  112. }
  113.  
  114. return 0;
  115.  
  116. }
  117.  
  118. void addrecord( )
  119.  
  120. {
  121.  
  122. system("cls");
  123.  
  124. FILE *fp ;
  125.  
  126. char another = 'Y' ,time[10];
  127.  
  128. struct record e ;
  129.  
  130. char filename[15];
  131.  
  132. int choice;
  133.  
  134. printf("\n\n\t\t***************************\n");
  135.  
  136. printf("\t\t* WELCOME TO THE ADD MENU *");
  137.  
  138. printf("\n\t\t***************************\n\n");
  139.  
  140. printf("\n\n\tENTER DATE OF YOUR RECORD:[yyyy-mm-dd]:");
  141.  
  142. fflush(stdin);
  143.  
  144. gets(filename);
  145.  
  146. fp = fopen (filename, "ab+" ) ;
  147.  
  148. if ( fp == NULL )
  149.  
  150. {
  151.  
  152. fp=fopen(filename,"wb+");
  153.  
  154. if(fp==NULL)
  155.  
  156. {
  157.  
  158. printf("\nSYSTEM ERROR...");
  159.  
  160. printf("\nPRESS ANY KEY TO EXIT");
  161.  
  162. getch();
  163.  
  164. return ;
  165.  
  166. }
  167.  
  168. }
  169.  
  170.  
  171.  
  172. while ( another == 'Y'|| another=='y' )
  173.  
  174. {
  175.  
  176. choice=0;
  177.  
  178. fflush(stdin);
  179.  
  180. printf ( "\n\tENTER TIME:[hh:mm]:");
  181.  
  182. scanf("%s",time);
  183.  
  184. rewind(fp);
  185.  
  186. while(fread(&e,sizeof(e),1,fp)==1)
  187.  
  188. {
  189.  
  190. if(strcmp(e.time,time)==0)
  191.  
  192. {
  193.  
  194. printf("\n\tTHE RECORD ALREADY EXISTS.\n");
  195.  
  196. choice=1;
  197.  
  198. }
  199.  
  200. }
  201.  
  202. if(choice==0)
  203.  
  204. {
  205.  
  206. strcpy(e.time,time);
  207.  
  208. printf("\tENTER NAME:");
  209.  
  210. fflush(stdin);
  211.  
  212. gets(e.name);
  213.  
  214. fflush(stdin);
  215.  
  216.  
  217. printf("\tNOTE:");
  218.  
  219. gets(e.note);
  220.  
  221. fwrite ( &e, sizeof ( e ), 1, fp ) ;
  222.  
  223. printf("\nYOUR RECORD IS ADDED...\n");
  224.  
  225. }
  226.  
  227. printf ( "\n\tADD ANOTHER RECORD...(Y/N) " ) ;
  228.  
  229. fflush ( stdin ) ;
  230.  
  231. another = getchar( ) ;
  232.  
  233. }
  234.  
  235.  
  236. fclose ( fp ) ;
  237.  
  238. printf("\n\n\tPRESS ANY KEY TO EXIT...");
  239.  
  240. getch();
  241.  
  242. }
  243.  
  244.  
  245. void viewrecord( )
  246.  
  247. {
  248.  
  249. FILE *fpte ;
  250.  
  251. system("cls");
  252.  
  253. struct record customer ;
  254.  
  255. char time[6],choice,filename[14];
  256.  
  257. int ch;
  258.  
  259. printf("\n\n\t\t*******************************\n");
  260.  
  261. printf("\t\t*Welcome to the View Menu*");
  262.  
  263. printf("\n\t\t*******************************\n\n");
  264. do
  265.  
  266. {
  267.  
  268. printf("\n\tENTER THE DATE OF RECORD TO BE VIEWED:[yyyy-mm-dd]:");
  269.  
  270. fflush(stdin);
  271.  
  272. gets(filename);
  273.  
  274.  
  275. fpte = fopen ( filename, "rb" ) ;
  276.  
  277. if ( fpte == NULL )
  278.  
  279. {
  280.  
  281. puts ( "\nTHE RECORD DOES NOT EXIST...\n" ) ;
  282.  
  283. printf("PRESS ANY KEY TO EXIT...");
  284.  
  285. getch();
  286.  
  287. return ;
  288.  
  289. }
  290.  
  291. system("cls");
  292.  
  293. printf("\n\tHOW WOULD YOU LIKE TO VIEW:\n");
  294.  
  295. printf("\n\t1.WHOLE RECORD OF THE DAY.");
  296.  
  297. printf("\n\t2.RECORD OF FIX TIME.");
  298.  
  299. printf("\n\t\tENTER YOUR CHOICE:");
  300.  
  301. scanf("%d",&ch);
  302.  
  303. switch(ch)
  304.  
  305. {
  306.  
  307. case 1:
  308.  
  309. printf("\nTHE WHOLE RECORD FOR %s IS:",filename);
  310.  
  311. while ( fread ( &customer, sizeof ( customer ), 1, fpte ) == 1 )
  312.  
  313. {
  314.  
  315. printf("\n");
  316.  
  317. printf("\nTIME: %s",customer.time);
  318.  
  319. printf("\nMEETING WITH: %s",customer.name);
  320. printf("\nNOTE: %s",customer.note);
  321.  
  322. printf("\n");
  323.  
  324. }
  325.  
  326. break;
  327.  
  328.  
  329. case 2:
  330.  
  331. fflush(stdin);
  332.  
  333. printf("\nENTER TIME:[hh:mm]:");
  334.  
  335. gets(time);
  336.  
  337. while ( fread ( &customer, sizeof ( customer ), 1, fpte ) == 1 )
  338.  
  339.  
  340. {
  341.  
  342. if(strcmp(customer.time,time)==0)
  343.  
  344. {
  345.  
  346. printf("\nYOUR RECORD IS:");
  347.  
  348. printf("\nTIME: %s",customer.time);
  349.  
  350. printf("\nMEETING WITH: %s",customer.name);
  351.  
  352. printf("\nNOTE: %s",customer.note);
  353.  
  354. }
  355.  
  356. }
  357.  
  358. break;
  359.  
  360.  
  361. default: printf("\nYOU TYPED SOMETHING ELSE...\n");
  362.  
  363. break;
  364.  
  365. }
  366.  
  367.  
  368. printf("\n\nWOULD YOU LIKE TO CONTINUE VIEWING...(Y/N):");
  369.  
  370. fflush(stdin);
  371.  
  372. scanf("%c",&choice);
  373.  
  374. }while(choice=='Y'||choice=='y');
  375.  
  376. fclose ( fpte ) ;
  377.  
  378. return ;
  379.  
  380. }
  381.  
  382.  
  383.  
  384. void editrecord()
  385.  
  386. {
  387.  
  388. system("cls");
  389.  
  390. FILE *fpte ;
  391.  
  392. struct record customer ;
  393.  
  394. char time[6],choice,filename[14];
  395.  
  396. int num,count=0;
  397.  
  398. printf("\n\n\t\t*****************\n");
  399.  
  400. printf("\t\t* Edit Menu *");
  401.  
  402. printf("\n\t\t*******************\n\n");
  403.  
  404. do
  405.  
  406. {
  407.  
  408. printf("\n\tENTER THE DATE OF RECORD TO BE EDITED:[yyyy-mm-dd]:");
  409.  
  410. fflush(stdin);
  411.  
  412. gets(filename);
  413.  
  414. printf("\n\tENTER TIME:[hh:mm]:");
  415.  
  416. gets(time);
  417.  
  418.  
  419. while ( fread ( &customer, sizeof ( customer ), 1, fpte ) == 1 )
  420.  
  421. {
  422.  
  423. if(strcmp(customer.time,time)==0)
  424.  
  425. {
  426.  
  427. printf("\nYOUR OLD RECORD WAS AS:");
  428.  
  429. printf("\nTIME: %s",customer.time);
  430.  
  431. printf("\nNOTE: %s",customer.note);
  432.  
  433.  
  434. printf("\n\n\t\tWHAT WOULD YOU LIKE TO EDIT..");
  435.  
  436. printf("\n1.TIME.");
  437.  
  438. printf("\n5.NOTE.");
  439.  
  440. printf("\n6.WHOLE RECORD.");
  441.  
  442. printf("\n7.GO BACK TO MAIN MENU.");
  443.  
  444. do
  445.  
  446. {
  447.  
  448. printf("\n\tENTER YOUR CHOICE:");
  449.  
  450. fflush(stdin);
  451.  
  452. scanf("%d",&num);
  453.  
  454. fflush(stdin);
  455.  
  456.  
  457. switch(num)
  458.  
  459. {
  460.  
  461. case 1: printf("\nENTER THE NEW DATA:");
  462.  
  463. printf("\nNEW TIME:[hh:mm]:");
  464.  
  465. gets(customer.time);
  466.  
  467. break;
  468.  
  469.  
  470. case 2: printf("\nENTER THE NEW DATA:");
  471.  
  472. printf("\nNEW MEETING PERSON:");
  473.  
  474. gets(customer.name);
  475.  
  476. break;
  477.  
  478. case 3: printf("ENTER THE NEW DATA:");
  479.  
  480. printf("\nNOTE:");
  481.  
  482. gets(customer.note);
  483.  
  484. break;
  485.  
  486.  
  487. case 4: printf("\nENTER THE NEW DATA:");
  488.  
  489. printf("\nNEW TIME:[hh:mm]:");
  490.  
  491. gets(customer.time);
  492.  
  493. printf("\nNEW MEETING PERSON:");
  494.  
  495. gets(customer.name);
  496.  
  497. printf("\nNOTE:");
  498.  
  499. gets(customer.note);
  500.  
  501. break;
  502.  
  503.  
  504. case 5: printf("\nPRESS ANY KEY TO GO BACK...\n");
  505.  
  506. getch();
  507.  
  508. return ;
  509.  
  510. break;
  511.  
  512.  
  513. default: printf("\nYOU TYPED SOMETHING ELSE...TRY AGAIN\n");
  514.  
  515. break;
  516.  
  517. }
  518.  
  519.  
  520. }while(num<1||num>8);
  521.  
  522. fseek(fpte,-sizeof(customer),SEEK_CUR);
  523.  
  524. fwrite(&customer,sizeof(customer),1,fpte);
  525.  
  526. fseek(fpte,-sizeof(customer),SEEK_CUR);
  527.  
  528. fread(&customer,sizeof(customer),1,fpte);
  529.  
  530. choice=5;
  531.  
  532. break;
  533.  
  534. }
  535.  
  536. }
  537.  
  538. if(choice==5)
  539.  
  540. {
  541.  
  542. system("cls");
  543.  
  544. printf("\n\t\tEDITING COMPLETED...\n");
  545.  
  546. printf("--------------------\n");
  547.  
  548. printf("THE NEW RECORD IS:\n");
  549.  
  550. printf("--------------------\n");
  551.  
  552. printf("\nTIME: %s",customer.time);
  553. printf("\nNOTE: %s",customer.note);
  554.  
  555. fclose(fpte);
  556.  
  557. printf("\n\n\tWOULD YOU LIKE TO EDIT ANOTHER RECORD.(Y/N)");
  558.  
  559. scanf("%c",&choice);
  560.  
  561. count++;
  562.  
  563. }
  564.  
  565.  
  566. }while(choice=='Y'||choice=='y');
  567.  
  568. fclose ( fpte ) ;
  569.  
  570.  
  571. if(count==1)
  572.  
  573. printf("\n%d FILE IS EDITED...\n",count);
  574.  
  575. else if(count>1)
  576.  
  577. printf("\n%d FILES ARE EDITED..\n",count);
  578.  
  579. else
  580.  
  581. printf("\nNO FILES EDITED...\n");
  582.  
  583. printf("\tPRESS ENTER TO EXIT EDITING MENU.");
  584.  
  585. getch();
  586.  
  587. }
  588.  
  589.  
  590. void deleterecord( )
  591.  
  592. {
  593.  
  594. system("cls");
  595.  
  596. FILE *fp,*fptr ;
  597.  
  598. struct record file ;
  599.  
  600. char filename[15],another = 'Y' ,time[10];;
  601.  
  602. int choice,check;
  603.  
  604. printf("\n\n\t\t*************************\n");
  605.  
  606. printf("\t\t* WELCOME TO DELETE MENU*");
  607.  
  608. printf("\n\t\t*************************\n\n");
  609.  
  610. while ( another == 'Y' )
  611.  
  612. {
  613.  
  614. printf("\n\n\tHOW WOULD YOU LIKE TO DELETE.");
  615.  
  616. printf("\n\n\t#DELETE WHOLE RECORD\t\t\t[1]");
  617.  
  618. printf("\n\t#DELETE A PARTICULAR RECORD BY TIME\t[2]");
  619.  
  620.  
  621. do
  622.  
  623. {
  624.  
  625. printf("\n\t\tENTER YOU CHOICE:");
  626.  
  627. scanf("%d",&choice);
  628.  
  629.  
  630. switch(choice)
  631.  
  632. {
  633.  
  634. case 1:
  635.  
  636. printf("\n\tENTER THE DATE OF RECORD TO BE DELETED:[yyyy-mm-dd]:");
  637.  
  638. fflush(stdin);
  639.  
  640. gets(filename);
  641.  
  642. fp = fopen (filename, "wb" ) ;
  643.  
  644. if ( fp == NULL )
  645.  
  646.  
  647.  
  648. fclose(fp);
  649.  
  650. remove(filename);
  651.  
  652. printf("\nDELETED SUCCESFULLY...");
  653.  
  654. break;
  655.  
  656.  
  657. case 2:
  658.  
  659. printf("\n\tENTER THE DATE OF RECORD:[yyyy-mm-dd]:");
  660.  
  661. fflush(stdin);
  662.  
  663. gets(filename);
  664.  
  665. fp = fopen (filename, "rb" ) ;
  666.  
  667. if ( fp == NULL )
  668.  
  669. {
  670.  
  671. printf("\nTHE FILE DOES NOT EXISTS");
  672.  
  673. printf("\nPRESS ANY KEY TO GO BACK.");
  674.  
  675. getch();
  676.  
  677. return ;
  678.  
  679. }
  680.  
  681.  
  682.  
  683. printf("\n\tENTER THE TIME OF RECORD TO BE DELETED:[hh:mm]:");
  684.  
  685. fflush(stdin);
  686.  
  687. gets(time);
  688.  
  689. while(fread(&file,sizeof(file),1,fp)==1)
  690.  
  691. {
  692.  
  693. if(strcmp(file.time,time)!=0)
  694.  
  695. fwrite(&file,sizeof(file),1,fptr);
  696.  
  697. }
  698.  
  699.  
  700. fclose(fp);
  701.  
  702. fclose(fptr);
  703.  
  704. remove(filename);
  705.  
  706. rename("temp",filename);
  707.  
  708. printf("\nDELETED SUCCESFULLY...");
  709.  
  710. break;
  711.  
  712.  
  713. default:
  714.  
  715. printf("\n\tYOU ENTERED WRONG CHOICE");
  716.  
  717. break;
  718.  
  719. }
  720.  
  721. }while(choice<1||choice>2);
  722.  
  723.  
  724.  
  725. printf("\n\tDO YOU LIKE TO DELETE ANOTHER RECORD.(Y/N):");
  726.  
  727. fflush(stdin);
  728.  
  729. scanf("%c",&another);
  730.  
  731. }
  732.  
  733. printf("\n\n\tPRESS ANY KEY TO EXIT...");
  734.  
  735. getch();
  736.  
  737. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement