Advertisement
Guest User

FORHELLO

a guest
Jun 5th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*The program below demonstrate a simple hospital management system that
  2.   allows user,doctor and admin to monitor it and perform features such
  3.             as adding,editing and editing patient's details*/
  4.  
  5. //  Project Title:     HOSPITAL MANAGEMENT SYSTEM
  6. //  Module Code:       AAPP005-4-2-PSPD
  7. //  Module Title:      Problem Solving & Program Designing using C
  8. //
  9. //  Name:              KHO ZHI YUEN
  10. //  TP Number:         TP038123
  11. //  Intake Code:       UCDF1505ICT(SE)
  12.  
  13.  
  14. /* ------------------------ Include Headers ------------------------*/
  15. #define _CRT_SECURE_NO_WARNINGS
  16. #include <stdio.h>      // Include the Standard Input/Output Header
  17. #include <stdlib.h>     // Include the Standard Library Header
  18. #include <unistd.h>     // Include the POSIX Standard Header
  19. #include <string.h>     // Include the Strings Header
  20. #include <ctype.h>      // Include the Header to Handle Characters
  21. #include <time.h>       // Include the Header to Manipulate Date and Time
  22. #include <stdbool.h>    // Include the Header for Boolean
  23. #include <windows.h>    // Include the Header for graphics
  24. #include <tchar.h>
  25.  
  26.  
  27. //ASCII CODE
  28. #define ENTER 13
  29. #define BKSP 8
  30. #define ESC 27
  31.  
  32. // ------------------------ Structures ------------------------//
  33. struct patient{
  34.     char pid[20];
  35.     char fname[50];
  36.     char lname[50];
  37.     char fullname[100];
  38.     char gender[10];
  39.     char age[3];
  40.     char address[30];
  41.     char contact[20];
  42. }patientdets,patienttemp; //patientdets hold patient data, patienttemp to hold temp data during transfer
  43.  
  44. struct app{
  45.     char pid[20];
  46.     char date[25];
  47.     char time[15];
  48.     char location[40];
  49.     char doctor[30];
  50.     char apptype[40];
  51. }appdets;               //appdets hold main appointment data
  52.  
  53. void structClean() {
  54.     strcpy(patientdets.fname, "");
  55.     strcpy(patientdets.lname, "");
  56.     strcpy(patientdets.fullname, "");
  57.     strcpy(patientdets.gender, "");
  58.     strcpy(patientdets.age, "");
  59.     strcpy(patientdets.address, "");
  60.     strcpy(patientdets.contact, "");
  61. }
  62.  
  63. struct user{
  64.     char u_name[25];
  65.     char u_pass[25];
  66. }u;
  67.  
  68. int choice;
  69. char *token;            //pointer for token to split up strings
  70. char *tokenA;           //pointer for token to split up strings in appointment
  71.  
  72. // ------------------------ Functions ------------------------//
  73. //MAIN MENU
  74. int menu();
  75. int receptionist();
  76. int doctor();
  77. void user();
  78. char *dataEntry(int type, int sizelimit);
  79. //SUB MENUS
  80. void receptionist_menu();   //Receptionist Menu
  81. void doctor_menu();         //Doctor Menu
  82. void receptionist_pat_menu(); //Receptionist Patient Menu
  83. void receptionist_app_menu(); //Receptionist Appointment Menu
  84. void doctor_pat_menu();       //Doctor Patient Menu
  85. void doctor_app_menu();       //Doctor Appointment Menu
  86. int patMenu();          //Patient's Menu
  87. int appMenu();          //Appointment's Menu
  88. //PATIENT MENU
  89. void addPat();          //Add Patient
  90. void viewPat();         //View Patient
  91. void searchPat();       //Search Patient
  92. void editPat();         //Edit Patient
  93. void deletePat();       //Delete Patient
  94. //APPOINTMENT MENU
  95. int addApp();           //Add Appointment
  96. void viewApp();         //View Appointment
  97. int searchApp();       //Search Appointment
  98. void editApp();       //Edit Appointment
  99. void deleteApp();       //Delete Appointment
  100. //SEARCH MENU
  101. int searchMAIN();       //Main coding for search functions
  102. void searchPID();       //Search via Patient's ID
  103. void searchNAME();      //Search via Patient's Name
  104. //FEEDBACK FORM
  105. void feedBack(){};     //To retrieve feedback from users
  106. //LOGIN FUNCTIONS
  107.  
  108. int  loginval();
  109. //VALIDATION FUNCTIONS
  110. int  escExit(char askey);
  111. int  backMenu(char askey);
  112. int  isalphaVal(char input[]);
  113. int  isdigitVal(char input[]);
  114. char *dataEntry(int type, int sizeLimit);
  115. //AUTO GENERATE PID FUNCTIONS
  116. int getLine();          //Get number of lines
  117. int getPID();           //Get PID
  118. //GOTOXY FUNCTION
  119. int usertype;
  120.  
  121. void structClean();
  122.  
  123.  
  124.  
  125. void gotoxy(int x, int y);
  126. COORD coord = {0,0};
  127. void gotoxy(int x, int y)
  128. {
  129.     coord.X = x;
  130.     coord.Y = y;
  131.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  132. }
  133. // ------------------------ Validations ------------------------//
  134. int escExit(char askey)
  135. {
  136.     char selection='Y';
  137.     if(askey==ESC)
  138.     {
  139.         do
  140.         {
  141.             if(!(toupper(selection)=='Y' || toupper(selection)=='N'))
  142.             {
  143.                 printf("\aINVALID INPUT!\n");
  144.             }
  145.             printf("\aDo you want to exit?\n");
  146.             selection = getch();
  147.         } while(!(toupper(selection)=='Y' || toupper(selection)=='N'));
  148.  
  149.             if(toupper(selection)=='Y')
  150.             {
  151.                 system("cls");
  152.                 exit(0);
  153.             }
  154.             else if(toupper(selection)=='N')
  155.             {
  156.                 system("cls");
  157.                 return 1;
  158.             }
  159.     }
  160. }
  161.  
  162. int backMenu(char askey)
  163. {
  164.     int result;
  165.  
  166.     if(askey==BKSP)
  167.     {
  168.         result = 1;
  169.     }
  170.     return result;
  171. }
  172.  
  173. char *dataEntry(int type, int sizeLimit)
  174. {
  175.     char input[30], p=' ';
  176.     int i=0;
  177.  
  178.     while(i<=sizeLimit)
  179.     {
  180.         input[i] = _getch();
  181.         p = input[i];
  182.  
  183.         if(i==sizeLimit)
  184.         {
  185.             if(p==ENTER)
  186.                 break;
  187.             else if((p>=48 && p<=57)||(p>=65 && p<=90)||(p>=97 && p<=122))
  188.                 {
  189.                 i--;
  190.                 printf("\b \b");
  191.                 }
  192.         }
  193.  
  194.         if(p!=13 && p!='\b' && !((p>=48 && p<=57)||(p>=65 && p<=90)||(p>=97 && p<=122)))
  195.         {
  196.             p='\0';
  197.         }
  198.  
  199.         else if(p==ENTER)
  200.         {
  201.             p='\0';
  202.             break;
  203.         }
  204.  
  205.         else if(p==BKSP)
  206.         {
  207.             i--;
  208.             if(i!=-1)
  209.             {
  210.                 p='\0';
  211.                 printf("\b \b");
  212.             }
  213.             else
  214.             {
  215.                 p='\0';
  216.                 i++;
  217.             }
  218.         }
  219.  
  220.         else
  221.         {
  222.             if(type==1)
  223.                 printf("%c", input[i]);
  224.             else if(type==2)
  225.                 printf("*");
  226.             else
  227.                 printf("\aINVALID INPUT!\n");
  228.             i++ ;
  229.         }
  230.     }
  231.     input[i] = '\0' ;
  232.     return input;
  233. }
  234.  
  235. int isalphaVal(char input[])
  236. {
  237.     int val,i;
  238.  
  239.     for(i=0;i<(strlen(input));i++)
  240.     {
  241.         if(isalpha(input[i])||(isspace(input[i])))
  242.             val=1;
  243.         else
  244.         {
  245.             val=0;
  246.             break;
  247.         }
  248.     }
  249.  
  250.     return val;
  251. }
  252.  
  253. int isdigitVal(char input[])
  254. {
  255.     int val, i;
  256.  
  257.     for(i=0;i<(strlen(input));i++)
  258.     {
  259.         if(input[i]>=48 && input[i]<=57)
  260.             val=1;
  261.         else
  262.         {
  263.             val=0;
  264.             break;
  265.         }
  266.     }
  267.     return val;
  268. }
  269.  
  270. int main()
  271. {
  272.     int a, b;
  273.     while(1)
  274.     {
  275.     do
  276.     {
  277.         system("cls");
  278.         system("color F0");
  279.         gotoxy(21,7);
  280.         printf("***************Welcome to SUMHEALTH**************");
  281.         gotoxy(33, 11);
  282.         printf("1. PRESS 1 FOR DOCTOR\n");
  283.         gotoxy(33, 12);
  284.         printf("2. PRESS 2 FOR RECEPTIONIST\n");
  285.         gotoxy(33, 13);
  286.         printf("3. PRESS 3 FOR USER");
  287.         gotoxy(21, 17);
  288.         printf("***************************************************");
  289.         gotoxy(33, 14);
  290.         printf("Enter your choice:");
  291.         scanf("%d", &usertype);
  292.         switch (usertype)
  293.         {
  294.             case 1: a = doctor();
  295.                     if (a != 0)
  296.                     doctor_menu();
  297.                     break;
  298.             case 2: b = receptionist();
  299.                     if (b != 0)
  300.                     receptionist_menu();
  301.                     break;
  302.             case 3: user();
  303.                     break;
  304.         }
  305.     }
  306.     while (usertype <1  ||  usertype > 3);
  307. }
  308. }
  309. int login_validation()
  310. {
  311.     FILE *fpass;
  312.  
  313.     char input_name[30], input_pass[30], action;
  314.     int login = 0, fail = 0;
  315.  
  316.     do{
  317.  
  318.         if(usertype == 1)
  319.             fpass = fopen("password1.txt", "r+");
  320.         else if(usertype == 2)
  321.             fpass = fopen("password2.txt", "r+");
  322.  
  323.             rewind(fpass);
  324.  
  325.         if(fpass != NULL)
  326.         {
  327.             system("cls");
  328.  
  329.         if(fail ==1)
  330.         {
  331.             gotoxy(25, 13);
  332.             printf("Error!");
  333.             gotoxy(25, 14);
  334.             printf("Please Enter Again!");
  335.         }
  336.  
  337.         system("color F1");
  338.         gotoxy(25, 8);
  339.         printf("************* WELCOME!****************");
  340.         int checker=0;
  341.         gotoxy(25, 12);
  342.         printf("Username: ");
  343.         fflush(stdin);
  344.         gets(input_name);
  345.         gotoxy(25, 13);
  346.         printf("Password: ");
  347.         fflush(stdin);
  348.         gets(input_pass);
  349.  
  350.             fscanf(fpass, "%s %s",u.u_name,u.u_pass);
  351.  
  352.             printf("%s",u.u_name);
  353.             printf("%s",u.u_pass);
  354.             fclose(fpass);
  355.             if((strcmp(u.u_name, input_name)==0) && (strcmp(u.u_pass, input_pass)==0))
  356.             {
  357.                 checker=1;
  358.             }
  359.  
  360.  
  361.         if(checker==1)
  362.             {
  363.                 printf("\a\n\nLogin Successful!");
  364.                 login=1;
  365.             }
  366.         else
  367.             fail=1;
  368.  
  369.  
  370.         }
  371.  
  372.         }while(login==0);
  373.         fclose(fpass);
  374.  
  375.         return 1;
  376.  
  377. }
  378. int doctor()
  379. {
  380.     int a = 0;
  381.     do
  382.     {
  383.  
  384.         system("cls");
  385.         fflush(stdin);
  386.         fflush(stdin);
  387.         a=login_validation();
  388.     }
  389.     while (a == 0);
  390.     return a;
  391. }
  392.  
  393. int receptionist()
  394. {
  395.     int a = 0;
  396.     do
  397.     {
  398.         system("cls");
  399.         fflush(stdin);
  400.         fflush(stdin);
  401.         a=login_validation();
  402.     }
  403.     while (a == 0);
  404.     return a;
  405. }
  406.  
  407. void user()
  408. {
  409.     printf("Hello");
  410. }
  411.  
  412. void doctor_menu()
  413. {
  414.     do
  415.     {
  416.         while(1)
  417.         {
  418.             system("cls");
  419.             system("color F5");
  420.             gotoxy(25, 8);
  421.             printf("----------DOCTOR MENU----------");
  422.             gotoxy(25, 10);
  423.             printf("1. Patient\n");
  424.             gotoxy(25, 11);
  425.             printf("2. Appointment\n");
  426.             gotoxy(25, 12);
  427.             printf("3. Logout");
  428.             gotoxy(25, 13);
  429.             printf("4. Exit");
  430.             gotoxy(25, 15);
  431.             printf("Enter your choice:");
  432.             scanf("%d", &choice);
  433.             switch (choice)
  434.             {
  435.                 case 1: doctor_pat_menu();
  436.                         break;
  437.                 case 2: doctor_app_menu();
  438.                         break;
  439.                 case 3: return 1;
  440.                 case 4: exit(0);
  441.  
  442.             }
  443.         }
  444.     }
  445.     while (choice <1  ||  choice > 4);
  446. }
  447.  
  448. void receptionist_menu()
  449. {
  450.     do
  451.     {
  452.         while(1)
  453.         {
  454.             system("cls");
  455.             system("color F8");
  456.             gotoxy(25, 8);
  457.             printf("----------RECEPTIONIST MENU----------");
  458.             gotoxy(25, 10);
  459.             printf("1. Patient\n");
  460.             gotoxy(25, 11);
  461.             printf("2. Appointment\n");
  462.             gotoxy(25, 12);
  463.             printf("3. Logout");
  464.             gotoxy(25, 13);
  465.             printf("4. Exit");
  466.             gotoxy(25, 14);
  467.             printf("Enter your choice:");
  468.             scanf("%d", &choice);
  469.             switch (choice)
  470.             {
  471.                 case 1: receptionist_pat_menu();
  472.                         break;
  473.                 case 2: receptionist_app_menu();
  474.                         break;
  475.                 case 3: return;
  476.                 case 4: exit(0);
  477.             }
  478.         }
  479.     }
  480.     while (choice <1  ||  choice > 2);
  481. }
  482. void doctor_pat_menu()
  483. {
  484.     do
  485.     {
  486.         while(1)
  487.         {
  488.             system("cls");
  489.             system("color FA");
  490.             gotoxy(25, 10);
  491.             printf("1. Search Patient\n");
  492.             gotoxy(25, 11);
  493.             printf("2. View Patient\n");
  494.             gotoxy(25, 12);
  495.             printf("3. Back\n");
  496.             gotoxy(25, 14);
  497.             printf("Enter your choice:");
  498.             scanf("%d", &choice);
  499.             switch (choice)
  500.             {
  501.                 case 1: searchPat();
  502.                         break;
  503.                 case 2: viewPat();
  504.                         break;
  505.                 case 3: return;
  506.             }
  507.         }
  508.     }
  509. while (choice <1  ||  choice > 2);
  510. }
  511.  
  512. void doctor_app_menu()
  513. {
  514.     do
  515.     {
  516.         while(1)
  517.         {
  518.             system("cls");
  519.             system("color FD");
  520.             gotoxy(25, 10);
  521.             printf("1. Search Appointment\n");
  522.             gotoxy(25, 11);
  523.             printf("2. View Appointment\n");
  524.             gotoxy(25, 12);
  525.             printf("3. Back\n");
  526.             gotoxy(25, 14);
  527.             printf("Enter your choice:");
  528.             scanf("%d", &choice);
  529.             switch (choice)
  530.             {
  531.                 case 1: searchApp();
  532.                         break;
  533.                 case 2: viewApp();
  534.                         break;
  535.                 case 3: return;
  536.             }
  537.         }
  538.     }
  539.     while (choice <1  ||  choice > 2);
  540. }
  541.  
  542. void receptionist_pat_menu()
  543. {
  544.     do
  545.     {
  546.         while(1)
  547.         {
  548.             system("cls");
  549.             system("color FB");
  550.             gotoxy(25, 8);
  551.             printf("1. Add New Patient\n");
  552.             gotoxy(25, 9);
  553.             printf("2. View Patient\n");
  554.             gotoxy(25, 10);
  555.             printf("3. Search Patient\n");
  556.             gotoxy(25, 11);
  557.             printf("4. Delete Patient\n");
  558.             gotoxy(25, 12);
  559.             printf("5. Modify Patient\n");
  560.             gotoxy(25, 13);
  561.             printf("6. Back\n");
  562.             gotoxy(25, 15);
  563.             printf("Enter your choice:");
  564.             fflush(stdin);
  565.             scanf("%d", &choice);
  566.             switch (choice)
  567.             {
  568.                 case 1: addPat();
  569.                         break;
  570.                 case 2: viewPat();
  571.                         break;
  572.                 case 3: searchPat();
  573.                         break;
  574.                 case 4: deletePat();
  575.                         break;
  576.                 case 5: editPat();
  577.                         break;
  578.                 case 6: return;
  579.             }
  580.  
  581.         }
  582.     }
  583.     while ((choice <1  ||  choice > 5));
  584. }
  585.  
  586. void receptionist_app_menu()
  587. {
  588.     do
  589.     {
  590.         while(1)
  591.         {
  592.             system("cls");
  593.             system("color FC");
  594.             gotoxy(25, 8);
  595.             printf("1. Add New Appointment\n");
  596.             gotoxy(25, 9);
  597.             printf("2. View Appointment\n");
  598.             gotoxy(25, 10);
  599.             printf("3. Search Appointment\n");
  600.             gotoxy(25, 11);
  601.             printf("4. Delete Appointment\n");
  602.             gotoxy(25, 12);
  603.             printf("5. Modify Appointment\n");
  604.             gotoxy(25 ,13);
  605.             printf("6. Back\n");
  606.             gotoxy(25, 15);
  607.             printf("Enter your choice:");
  608.             fflush(stdin);
  609.             scanf("%d", &choice);
  610.             switch (choice)
  611.             {
  612.                 case 1: addApp();
  613.                         break;
  614.                 case 2: viewApp();
  615.                         break;
  616.                 case 3: searchApp();
  617.                         break;
  618.                 case 4: deleteApp();
  619.                         break;
  620.  
  621.                 case 5: editApp();
  622.                         break;
  623.                 case 6: return;
  624.             }
  625.             system("pause");
  626.         }
  627.     }
  628.     while ((choice <1 || choice > 6));
  629. }
  630.  
  631.  
  632. int getLine()
  633. {
  634.     int i=1;
  635.     char ch;
  636.  
  637.     FILE *fpatient;
  638.     fpatient=fopen("PATIENT.txt","r");
  639.  
  640.     if(fpatient!=NULL)
  641.     {
  642.         while(!feof(fpatient))
  643.         {
  644.             ch = fgetc(fpatient);
  645.             if (ch=='\n')
  646.                 i++;
  647.         }
  648.     }
  649.  
  650.     else
  651.     {
  652.         perror("ERROR\n");
  653.         return(-1);
  654.     }
  655.     fclose(fpatient);
  656.     return i;
  657. }
  658.  
  659. int getPID()
  660. {
  661.     int i = getLine();
  662.     strcpy(patientdets.pid, "");
  663.     sprintf(patientdets.pid,"TP%004d",i);
  664.     return i;
  665. }
  666.  
  667. char *getFirstName()
  668. {
  669.     int val=0;
  670.      char first[20];
  671.     do
  672.     {
  673.         printf("Enter First Name:\n");
  674.         gets(first);
  675.         val=isalphaVal(first);
  676.     }while(val==0);
  677.     return first;
  678. }
  679.  
  680. char *getLastName()
  681. {
  682.     int val=0;
  683.      char last[20];
  684.     do
  685.     {
  686.         printf("Enter Last Name:\n");
  687.         gets(last);
  688.         val=isalphaVal(last);
  689.     }while(val==0);
  690.     return last;
  691. }
  692.  
  693.  
  694. char *getFullName()
  695. {
  696.      char full[50];
  697.     printf("Insert Full name:\n");
  698.     gets(full);
  699.     return full;
  700. }
  701. char *getGender()
  702. {
  703.      char gender[5];
  704.     printf("Enter Gender:\n");
  705.     gets(gender);
  706.     return gender;
  707. }
  708.  
  709. char *getAge()
  710. {
  711.     int val=0;
  712.      char age[3];
  713.     do
  714.     {
  715.         printf("Enter Age:\n");
  716.         gets(age);
  717.         val=isdigitVal(age);
  718.     }while(val==0);
  719.     return age;
  720. }
  721.  
  722. char *getAddress()
  723. {
  724.      char address[30];
  725.     printf("Enter Address:\n");
  726.     gets(address);
  727.     return address;
  728. }
  729.  
  730. char *getContact()
  731. {
  732.     int val=0;
  733.      char contact[20];
  734.     do
  735.     {
  736.         printf("Enter Contact:\n");
  737.         gets(contact);
  738.         val=isdigitVal(contact);
  739.     }while(val==0);
  740.     return contact;
  741. }
  742.  
  743. char *getDate()
  744. {
  745.     int val=0;
  746.      char day[4];
  747.      char month[4];
  748.      char year[8];
  749.      char date[25];
  750.     char slash[2]="/";
  751.     char sslash[2]="/";
  752.     printf("Enter App. Day:\n");
  753.     gets(day);
  754.     printf("Enter App. Month:\n");
  755.     gets(month);
  756.     printf("Enter App. Year:\n");
  757.     gets(year);
  758.  
  759.     strcpy(date,"");
  760.     strcat(date,day);
  761.     strcat(date,sslash);
  762.     strcat(date,month);
  763.     strcat(date,slash);
  764.     strcat(date,year);
  765.     return date;
  766. }
  767.  
  768. char *getTime()
  769. {
  770.     char time[15];
  771.     char hour[5];
  772.     char mins[5];
  773.     char type[3];
  774.     char dot[2]=":";
  775.  
  776.     printf("Enter App. Hour:\n");
  777.     gets(hour);
  778.     printf("Enter App. Minutes:\n");
  779.     gets(mins);
  780.     printf("(AM/PM):\n");
  781.     gets(type);
  782.  
  783.     strcpy(time,"");
  784.     strcat(time,hour);
  785.     strcat(time,dot);
  786.     strcat(time,mins);
  787.     strcat(time,type);
  788.     return time;
  789. }
  790.  
  791. char *getLocation()
  792. {
  793.     char location[40];
  794.     printf("Enter App. Location:\n");
  795.     gets(location);
  796.     return location;
  797. }
  798.  
  799. char *getDoctor()
  800. {
  801.     char doctor[30];
  802.     printf("Enter App. Doctor:\n");
  803.     gets(doctor);
  804.     return doctor;
  805. }
  806.  
  807. char *getAppType()
  808. {
  809.      int app;
  810.      char sp[]="Specialist";
  811.      char no[]="Normal";
  812.      char he[]="Health Test";
  813.      printf("Choose Appointment Type:\n(1)Specialist\t(2)Normal\t(3)Health Test\n");
  814.      scanf("%d",&app);
  815.      switch(app)
  816.      {
  817.          case 1:
  818.             {
  819.                 return(sp);
  820.             }
  821.          case 2:
  822.             {
  823.                 return(no);
  824.             }
  825.          case 3:
  826.             {
  827.                 return(he);
  828.             }
  829.          default:
  830.             {
  831.                 perror("PLEASE ENTER A VALID NUMBER!\n");
  832.                 return(-1);
  833.             }
  834.      }
  835.  
  836. }
  837.  
  838. void addPat()
  839. {
  840.     system("color FC");
  841.     int i = 0;
  842.     char z[30] = " ";
  843.     int selection = 'N';
  844.  
  845.     FILE *fpatient;
  846.  
  847.     do
  848.     {
  849.         structClean();
  850.         fpatient = fopen("PATIENT.txt", "a");
  851.  
  852.         if (fpatient==NULL)
  853.         {
  854.             perror("FILE DOES NOT EXISTS!\n");
  855.             return ;
  856.         }
  857.         else
  858.         {
  859.             system("cls");
  860.             i = getPID();
  861.             printf("Patient ID:%s\n",patientdets.pid);
  862.             fflush(stdin);
  863.             strcpy(patientdets.fname,getFirstName());
  864.             strcpy(patientdets.lname,getLastName());
  865.             strcat(z,patientdets.lname);
  866.             strcat(patientdets.fname,z);
  867.             strcpy(patientdets.fullname,patientdets.fname);
  868.             strcpy(patientdets.gender,getGender());
  869.             strcpy(patientdets.age,getAge());
  870.             strcpy(patientdets.address,getAddress());
  871.             strcpy(patientdets.contact,getContact());
  872.             fprintf(fpatient,"%s-->%s-->%s-->%s-->%s-->%s\n",patientdets.pid,patientdets.fullname,patientdets.gender,patientdets.age,patientdets.address,patientdets.contact);
  873.             printf("\nDo You Want To Add Another Patient's Details? (Y/N):");
  874.             fflush(stdin);
  875.             selection = getchar();
  876.             fclose(fpatient);
  877.         }
  878.  
  879.     }while(selection == 'Y' || selection == 'y');
  880.  
  881.     return ;
  882. }
  883.  
  884. void viewPat()
  885. {
  886.     system("cls");
  887.     char buffer[1024]=" ";
  888.     char s[4] = "-->";
  889.     char *token;
  890.     int counter = 1;
  891.     FILE *fpatient;
  892.  
  893.     fpatient = fopen("PATIENT.txt","r");
  894.  
  895.     if (fpatient == NULL)
  896.     {
  897.         printf("ERROR:FILE CANNOT BE OPENED!\n");
  898.     }
  899.     else
  900.     {
  901.         if (feof(fpatient))
  902.         {
  903.             printf("ERROR:END OF FILE!\n");
  904.         }
  905.         else
  906.         {
  907.             while( fgets(buffer,1024,fpatient) != NULL )
  908.             {
  909.                 token = strtok(buffer, s);
  910.                 strcpy(patientdets.pid,token);
  911.                 token = strtok(NULL,s);
  912.                 strcpy(patientdets.fullname,token);
  913.                 token = strtok(NULL,s);
  914.                 strcpy(patientdets.gender,token);
  915.                 token = strtok(NULL,s);
  916.                 strcpy(patientdets.age,token);
  917.                 token = strtok(NULL,s);
  918.                 strcpy(patientdets.address,token);
  919.                 token = strtok(NULL,s);
  920.                 strcpy(patientdets.contact,token);
  921.                 token = strtok(NULL,s);
  922.  
  923.                 printf("Patient's ID:       %s\n",patientdets.pid);
  924.                 printf("Patient's name:     %s\n",patientdets.fullname);
  925.                 printf("Patient's gender:   %s\n",patientdets.gender);
  926.                 printf("Patient's age:      %s\n",patientdets.age);
  927.                 printf("Patient's address:  %s\n",patientdets.address);
  928.                 printf("Patient's contract: %s\n",patientdets.contact);
  929.                 printf("------------------------------------------------------\n");
  930.             }
  931.  
  932.         }
  933.     }
  934.     fclose(fpatient);
  935.     printf("\n");
  936.     system("pause");
  937. }
  938.  
  939. void searchPat()
  940. {
  941.     do
  942.     {
  943.         system("cls");
  944.         printf("---------- SEARCH MAIN MENU ----------\n");
  945.         printf("(1)SEARCH PID\n(2)SEARCH NAME\n(3)RETURN TO MAIN\n(4)LOGOUT\n");
  946.         do
  947.         {
  948.             printf("CHOICE:");
  949.             scanf("%d", &choice);
  950.         }while(choice<1 || choice > 4);
  951.  
  952.         switch (choice)
  953.         {
  954.             case 1:
  955.             {
  956.                 searchPID();
  957.                 break;
  958.             }
  959.             case 2:
  960.             {
  961.                 searchNAME();
  962.                 break;
  963.             }
  964.             case 3:
  965.             {
  966.                 return;
  967.             }
  968.             case 4:
  969.             {
  970.                 exit(0);
  971.             }
  972.             default:
  973.             {
  974.                 printf("PLEASE ENTER A VALID NUMBER!\n");
  975.                 break;
  976.             }
  977.         }
  978.         system("pause");
  979.  
  980.     }while (1 == 1);
  981. }
  982.  
  983. int searchMAIN()
  984. {
  985.     int i;
  986.     const char s[4] = "-->";
  987.     char *token;
  988.     int done = 0;
  989.  
  990.     FILE *fpatient;
  991.     fpatient = fopen("PATIENT.txt","r+");
  992.     if(fpatient==NULL)
  993.     {
  994.         perror("FILE CANNOT OPEN\n");
  995.         return(-1);
  996.     }
  997.     else
  998.     {
  999.         char buffer[200];
  1000.         char input[20];
  1001.         char tok[200];
  1002.         int line=0;
  1003.  
  1004.         printf("ENTER ID: ");
  1005.         fflush(stdin);
  1006.         scanf("%20s",input);
  1007.         while(fgets(buffer,200,fpatient) != NULL)
  1008.         {
  1009.  
  1010.             line++;
  1011.             token = strtok(buffer, s);
  1012.             if (strcmp(token,input)==0)
  1013.             {
  1014.                 strcpy(patientdets.pid,token);
  1015.                 token = strtok(NULL,s);
  1016.                 strcpy(patientdets.fullname,token);
  1017.                 token = strtok(NULL,s);
  1018.                 strcpy(patientdets.gender,token);
  1019.                 token = strtok(NULL,s);
  1020.                 strcpy(patientdets.age,token);
  1021.                 token = strtok(NULL,s);
  1022.                 strcpy(patientdets.address,token);
  1023.                 token = strtok(NULL,s);
  1024.                 strcpy(patientdets.contact,token);
  1025.                 token = strtok(NULL,s);
  1026.  
  1027.                 fclose(fpatient);
  1028.                 return line;
  1029.             }
  1030.         }
  1031.         if(feof(fpatient))
  1032.         {
  1033.             printf("\n**SEARCH COMPLETED!**\n");
  1034.         }
  1035.  
  1036.     }
  1037.     fclose(fpatient);
  1038.     return -1;
  1039. }
  1040.  
  1041. void searchPID()
  1042. {
  1043.     int found = 0;
  1044.     found = searchMAIN();
  1045.     if (found != -1)
  1046.     {
  1047.         printf("Patient ID:     %s\n",patientdets.pid);
  1048.         printf("Fullname  :     %s\n",patientdets.fullname);
  1049.         printf("Gender    :     %s\n",patientdets.gender);
  1050.         printf("Age       :     %s\n",patientdets.age);
  1051.         printf("Address   :     %s\n",patientdets.address);
  1052.         printf("Contact   :     %s\n",patientdets.contact);
  1053.     }
  1054.     else
  1055.     {
  1056.         printf("\n\nID NOT DETECTED\n!");
  1057.     }
  1058. }
  1059.  
  1060. void searchNAME()
  1061. {
  1062.     const char s[4] = "-->";
  1063.     char *token;
  1064.  
  1065.     FILE *fpatient;
  1066.     fpatient = fopen("PATIENT.txt","r+");
  1067.     if(fpatient==NULL)
  1068.     {
  1069.         perror("FILE CANNOT OPEN\n");
  1070.         exit(1);
  1071.     }
  1072.     else
  1073.     {
  1074.         char buffer[1024];
  1075.         char input[1024];
  1076.         char tok[512];
  1077.         int done = 0;
  1078.  
  1079.         printf("ENTER NAME: ");
  1080.         fflush(stdin);
  1081.         gets(input);
  1082.         while(fgets(buffer,1024,fpatient) != NULL)
  1083.         {
  1084.             strcpy(tok,buffer);
  1085.             token = strtok(tok,s);
  1086.             token = strtok(NULL,s);
  1087.  
  1088.             if(strstr(token,input)!=NULL)
  1089.             {
  1090.                 token = strtok(buffer, s);
  1091.                 strcpy(patientdets.pid,token);
  1092.                 token = strtok(NULL,s);
  1093.                 strcpy(patientdets.fullname,token);
  1094.                 token = strtok(NULL,s);
  1095.                 strcpy(patientdets.gender,token);
  1096.                 token = strtok(NULL,s);
  1097.                 strcpy(patientdets.age,token);
  1098.                 token = strtok(NULL,s);
  1099.                 strcpy(patientdets.address,token);
  1100.                 token = strtok(NULL,s);
  1101.                 strcpy(patientdets.contact,token);
  1102.                 token = strtok(NULL,s);
  1103.  
  1104.                 printf("Patient ID:     %s\n",patientdets.pid);
  1105.                 printf("Fullname  :     %s\n",patientdets.fullname);
  1106.                 printf("Gender    :     %s\n",patientdets.gender);
  1107.                 printf("Age       :     %s\n",patientdets.age);
  1108.                 printf("Address   :     %s\n",patientdets.address);
  1109.                 printf("Contact   :     %s\n",patientdets.contact);
  1110.  
  1111.                 done =1;
  1112.             }
  1113.         }
  1114.         if(feof(fpatient))
  1115.         {
  1116.              printf("\nSearch complete\n");
  1117.         }
  1118.         else
  1119.         {
  1120.             printf("\nFile can't be searched completely ");
  1121.             exit(1);
  1122.         }
  1123.     if (done!=1)
  1124.     {
  1125.         printf("Name cannot be found");
  1126.     }
  1127.     }
  1128. }
  1129.  
  1130. void editPat()
  1131. {
  1132.     FILE *fpatient;
  1133.     FILE *ftemp;
  1134.     int found=0,choice=0,line=0,i=0;
  1135.     char selection=0,ch;
  1136.     char buff[512]="",buff2[512];
  1137.     found = searchMAIN();
  1138.     if (found != -1)
  1139.     {
  1140.         fflush(stdin);
  1141.         printf("Is this the patient ID you want to modify? (Y/N)\n");
  1142.         printf("Patient ID:     %s\n",patientdets.pid);
  1143.         printf("Fullname  :     %s\n",patientdets.fullname);
  1144.         printf("Gender    :     %s\n",patientdets.gender);
  1145.         printf("Age       :     %s\n",patientdets.age);
  1146.         printf("Address   :     %s\n",patientdets.address);
  1147.         printf("Contact   :     %s\n",patientdets.contact);
  1148.         printf("CHOICE:");
  1149.         scanf("%c",&selection);
  1150.         if(toupper(selection)== 'Y')
  1151.         {
  1152.             fpatient=fopen("PATIENT.txt","a+");
  1153.             ftemp=fopen("editPatient.txt","w");
  1154.  
  1155.             while(!feof(fpatient))
  1156.             {
  1157.                 ch = fgetc(fpatient);
  1158.                 if(ch == '\n')
  1159.                     i++;
  1160.             }
  1161.  
  1162.             printf("(1)Full Name\n");printf("(2)Gender\n");printf("(3)Age\n");printf("(4)Address\n");printf("(5)Contact\n");printf("(0)Back\n");
  1163.             printf("Select option to be modified:");
  1164.             scanf("%d",&choice);
  1165.             switch(choice)
  1166.             {
  1167.                 case 1:
  1168.                 {
  1169.                     fflush(stdin);
  1170.                     strcpy(patientdets.fullname,getFullName());
  1171.                     break;
  1172.                 }
  1173.                 case 2:
  1174.                 {
  1175.                     fflush(stdin);
  1176.                     strcpy(patientdets.gender,getGender());
  1177.                     printf("%s",patienttemp.gender);
  1178.                     break;
  1179.                 }
  1180.                 case 3:
  1181.                 {
  1182.                     fflush(stdin);
  1183.                     strcpy(patientdets.age,getAge());
  1184.                     break;
  1185.                 }
  1186.                 case 4:
  1187.                 {
  1188.                     fflush(stdin);
  1189.                     strcpy(patientdets.address,getAddress());
  1190.                     break;
  1191.                 }
  1192.                 case 5:
  1193.                 {
  1194.                     fflush(stdin);
  1195.                     strcpy(patientdets.contact,getContact());
  1196.                     break;
  1197.                 }
  1198.  
  1199.             }
  1200.             strcat(buff, patientdets.pid);strcat(buff,"-->");
  1201.             strcat(buff, patientdets.fullname);strcat(buff, "-->");
  1202.             strcat(buff, patientdets.gender);strcat(buff, "-->");
  1203.             strcat(buff, patientdets.age);strcat(buff, "-->");
  1204.             strcat(buff, patientdets.address);strcat(buff,"-->");
  1205.             strcat(buff, patientdets.contact);
  1206.  
  1207.             printf("%s",buff);
  1208.  
  1209.             rewind(fpatient);
  1210.             while (line<i)
  1211.             {
  1212.  
  1213.                 line++;
  1214.                 if(found == line)
  1215.                 {
  1216.                     fputs(buff,ftemp);
  1217.                     fgets(buff2,512,fpatient); // store current line into buffer2
  1218.                 }
  1219.                 else
  1220.                 {
  1221.                     fgets(buff2,512,fpatient);
  1222.                     fputs(buff2,ftemp);
  1223.                 }
  1224.  
  1225.             }
  1226.             fclose(fpatient);
  1227.             fclose(ftemp);
  1228.             remove("PATIENT.txt");
  1229.             rename("editPatient.txt","PATIENT.txt");
  1230.         }
  1231.         else
  1232.         {
  1233.             printf("SEE YOU AGAIN!");
  1234.             return;
  1235.             system("pause");
  1236.         }
  1237.     }
  1238.     else
  1239.     {
  1240.         printf("\n\nID NOT DETECTED\n!");
  1241.     }
  1242.     system("pause");
  1243. }
  1244.  
  1245.  
  1246.  
  1247. void deletePat()
  1248. {
  1249.     FILE *fpatient;
  1250.     fpatient = fopen("PATIENT.txt","r");
  1251.     if(fpatient==NULL)
  1252.     {
  1253.         printf("FILE CANNOT BE OPENED!\n");
  1254.         exit(1);
  1255.     }
  1256.     else
  1257.     {
  1258.         int line=0;
  1259.         char selection;
  1260.         line = searchMAIN();
  1261.         rewind(fpatient);
  1262.         if(line != -1)
  1263.         {
  1264.             printf("Patient ID:     %s\n",patientdets.pid);
  1265.             printf("Fullname  :     %s\n",patientdets.fullname);
  1266.             printf("Gender    :     %s\n",patientdets.gender);
  1267.             printf("Age       :     %s\n",patientdets.age);
  1268.             printf("Address   :     %s\n",patientdets.address);
  1269.             printf("Contact   :     %s\n",patientdets.contact);
  1270.             printf("Are you sure you wanted to delete this patient?\n");
  1271.             fflush(stdin);
  1272.             printf("CHOICE:");
  1273.             selection=getchar();
  1274.             if(toupper(selection)=='Y')
  1275.             {
  1276.                 char words[100];
  1277.                 char *buffer;
  1278.                 char *ptr;
  1279.                 int  read_line=0;
  1280.                 char user_input[100];
  1281.                 int  done=0;
  1282.  
  1283.                 buffer=(char *)malloc(1000*sizeof(char));
  1284.                 memset(buffer,0,1000*sizeof(char));
  1285.                 ptr=buffer;
  1286.  
  1287.                 strcat(patientdets.pid,"\n");
  1288.  
  1289.                 while(fgets(words,100,fpatient) != NULL)
  1290.                 {
  1291.                     read_line ++;
  1292.                     if(read_line != line)
  1293.                     {
  1294.                         strcpy(ptr,words);
  1295.                         ptr +=strlen(words);
  1296.                     }
  1297.                 }
  1298.                 fclose(fpatient);
  1299.  
  1300.                 fpatient=fopen("PATIENT.txt","w");
  1301.                 fprintf(fpatient,"%s",buffer);
  1302.                 fclose(fpatient);
  1303.             }
  1304.         }
  1305.     }
  1306.     system("pause");
  1307. }
  1308.  
  1309. int addApp()
  1310. {
  1311.     FILE *fApp;
  1312.     int found=-1;
  1313.     char selection;
  1314.  
  1315.     found = searchMAIN();
  1316.     if (found >= 0)
  1317.     {
  1318.         printf("Add appointment for this patient? (Y/N)\n");
  1319.         printf("Patient ID:     %s\n",patientdets.pid);
  1320.         printf("Fullname  :     %s\n",patientdets.fullname);
  1321.         printf("Gender    :     %s\n",patientdets.gender);
  1322.         printf("Age       :     %s\n",patientdets.age);
  1323.         printf("Address   :     %s\n",patientdets.address);
  1324.         printf("Contact   :     %s\n",patientdets.contact);
  1325.         fflush(stdin);
  1326.         scanf("%c",&selection);
  1327.         if(toupper(selection)=='Y')
  1328.         {
  1329.             fApp=fopen("APP.txt","a");
  1330.  
  1331.             strcpy(appdets.pid,patientdets.pid);
  1332.             fflush(stdin);
  1333.             strcpy(appdets.date,getDate());
  1334.             fflush(stdin);
  1335.             strcpy(appdets.time,getTime());
  1336.             fflush(stdin);
  1337.             strcpy(appdets.location,getLocation());
  1338.             fflush(stdin);
  1339.             strcpy(appdets.doctor,getDoctor());
  1340.             fflush(stdin);
  1341.             strcpy(appdets.apptype,getAppType());
  1342.             fprintf(fApp,"%s-->%s-->%s-->%s-->%s-->%s\n",appdets.pid,appdets.date,appdets.time,appdets.location,appdets.doctor,appdets.apptype);
  1343.             fclose(fApp);
  1344.         }
  1345.         else
  1346.         {
  1347.             printf("<-Back");
  1348.             return 1;
  1349.         }
  1350.     }
  1351.     return 0;
  1352.     system("pause");
  1353. }
  1354.  
  1355. void viewApp()
  1356. {
  1357.     system("cls");
  1358.     char buffer[1024]=" ";
  1359.     char s[4] = "-->";
  1360.     char *token;
  1361.     int counter = 1;
  1362.  
  1363.     FILE *fApp;
  1364.     fApp = fopen("APP.txt","r");
  1365.  
  1366.     if (fApp == NULL)
  1367.     {
  1368.         printf("ERROR:FILE CANNOT BE OPENED!\n");
  1369.     }
  1370.     else
  1371.     {
  1372.         if (feof(fApp))
  1373.         {
  1374.             printf("ERROR:END OF FILE!\n");
  1375.             fclose(fApp);
  1376.         }
  1377.         else
  1378.         {
  1379.             while( fgets(buffer,1024,fApp) != NULL )
  1380.             {
  1381.                 token = strtok(buffer, s);
  1382.                 strcpy(appdets.pid,token);
  1383.                 token = strtok(NULL,s);
  1384.                 strcpy(appdets.date,token);
  1385.                 token = strtok(NULL,s);
  1386.                 strcpy(appdets.time,token);
  1387.                 token = strtok(NULL,s);
  1388.                 strcpy(appdets.location,token);
  1389.                 token = strtok(NULL,s);
  1390.                 strcpy(appdets.doctor,token);
  1391.                 token = strtok(NULL,s);
  1392.                 strcpy(appdets.apptype,token);
  1393.                 token = strtok(NULL,s);
  1394.  
  1395.                 printf("Patient's ID: %s\n",appdets.pid);
  1396.                 printf("Appointment's Date: %s\n",appdets.date);
  1397.                 printf("Appointment's Time: %s\n",appdets.time);
  1398.                 printf("Appointment's Location: %s\n",appdets.location);
  1399.                 printf("Doctor In Charge: %s\n",appdets.doctor);
  1400.                 printf("Appointment's Type: %s\n",appdets.apptype);
  1401.                 printf("------------------------------------------------------\n");
  1402.             }
  1403.             fclose(fApp);
  1404.         }
  1405.     }
  1406.     printf("\n");
  1407.     system("pause");
  1408. }
  1409.  
  1410. int searchApp()
  1411. {
  1412.     system("cls");
  1413.     char buffer[1024]=" ";
  1414.     char s[4] = "-->";
  1415.     char *token;
  1416.     int counter = 0;
  1417.     char tempID[100] ;
  1418.  
  1419.     FILE *fApp;
  1420.     fApp = fopen("APP.txt","r");
  1421.  
  1422.     if (fApp == NULL)
  1423.     {
  1424.         printf("ERROR:FILE CANNOT BE OPENED!\n");
  1425.     }
  1426.     else
  1427.     {
  1428.         if (feof(fApp))
  1429.         {
  1430.             printf("ERROR:END OF FILE!\n");
  1431.             fclose(fApp);
  1432.         }
  1433.         else
  1434.         {
  1435.             printf("ENTER ID: ");
  1436.             fflush(stdin);
  1437.             gets(tempID);
  1438.  
  1439.             while( fgets(buffer,1024,fApp) != NULL )
  1440.             {
  1441.                 counter ++ ;
  1442.                 token = strtok(buffer, s);
  1443.                 if ( strcmp(token,tempID)== 0)
  1444.                 {
  1445.                     strcpy(appdets.pid,token);
  1446.                     token = strtok(NULL,s);
  1447.                     strcpy(appdets.date,token);
  1448.                     token = strtok(NULL,s);
  1449.                     strcpy(appdets.time,token);
  1450.                     token = strtok(NULL,s);
  1451.                     strcpy(appdets.location,token);
  1452.                     token = strtok(NULL,s);
  1453.                     strcpy(appdets.doctor,token);
  1454.                     token = strtok(NULL,s);
  1455.                     strcpy(appdets.apptype,token);
  1456.                     token = strtok(NULL,s);
  1457.  
  1458.                     printf("Patient's ID:           %s\n",appdets.pid);
  1459.                     printf("Appointment's Date:     %s\n",appdets.date);
  1460.                     printf("Appointment's Time:     %s\n",appdets.time);
  1461.                     printf("Appointment's Location: %s\n",appdets.location);
  1462.                     printf("Doctor In Charge:       %s\n",appdets.doctor);
  1463.                     printf("Appointment's Type:     %s\n",appdets.apptype);
  1464.                     printf("------------------------------------------------------\n");
  1465.  
  1466.                     return counter;
  1467.                 }
  1468.             }
  1469.             fclose(fApp);
  1470.         }
  1471.     }
  1472.     printf("Can't find appointment");
  1473.     system("pause");
  1474.  
  1475.     return counter;
  1476.  
  1477. }
  1478.  
  1479. void editApp()
  1480. {
  1481.     FILE *fApp;
  1482.     FILE *fTemp;
  1483.     int found=0,choice=0,line=0,i;
  1484.     char selection=0,ch;
  1485.     char buff[512]="", buff2[512]="";
  1486.     found = searchApp();
  1487.     if (found != -1)
  1488.     {
  1489.         fflush(stdin);
  1490.         system("cls");
  1491.         printf("%d\n\n",found);
  1492.         printf("Patient's ID:           %s\n",appdets.pid);
  1493.         printf("Appointment's Date:     %s\n",appdets.date);
  1494.         printf("Appointment's Time:     %s\n",appdets.time);
  1495.         printf("Appointment's Location: %s\n",appdets.location);
  1496.         printf("Doctor In Charge:       %s\n",appdets.doctor);
  1497.         printf("Appointment's Type:     %s\n",appdets.apptype);
  1498.         printf("------------------------------------------------------\n");
  1499.         printf("Are you sure you wanted to edit this appointment?\n");
  1500.         printf("CHOICE:");
  1501.         scanf(" %c",&selection);
  1502.         if(toupper(selection)== 'Y')
  1503.         {
  1504.             fApp=fopen("APP.txt","a+");
  1505.             fTemp=fopen("editApp.txt","w");
  1506.             printf("(1)Date\n");printf("(2)Time\n");printf("(3)Location\n");printf("(4)Doctor\n");printf("(5)Apptype\n");printf("(0)Back\n");
  1507.             printf("Select option to be modified:");
  1508.             scanf("%d",&choice);
  1509.             switch(choice)
  1510.             {
  1511.                 case 1:
  1512.                 {
  1513.                     fflush(stdin);
  1514.                     strcpy(appdets.date,getDate());
  1515.                     break;
  1516.                 }
  1517.                 case 2:
  1518.                 {
  1519.                     fflush(stdin);
  1520.                     strcpy(appdets.time,getTime());
  1521.                     break;
  1522.                 }
  1523.                 case 3:
  1524.                 {
  1525.                     fflush(stdin);
  1526.                     strcpy(appdets.location,getLocation());
  1527.                     break;
  1528.                 }
  1529.                 case 4:
  1530.                 {
  1531.                     fflush(stdin);
  1532.                     strcpy(appdets.doctor,getDoctor());
  1533.                     break;
  1534.                 }
  1535.                 case 5:
  1536.                 {
  1537.                     fflush(stdin);
  1538.                     strcpy(appdets.apptype,getAppType());
  1539.                     break;
  1540.                 }
  1541.  
  1542.             }
  1543.             strcat(buff, appdets.pid);strcat(buff,"-->");
  1544.             strcat(buff, appdets.date);strcat(buff, "-->");
  1545.             strcat(buff, appdets.time);strcat(buff, "-->");
  1546.             strcat(buff, appdets.location);strcat(buff, "-->");
  1547.             strcat(buff, appdets.doctor);strcat(buff,"-->");
  1548.             strcat(buff, appdets.apptype);
  1549.  
  1550.             rewind(fApp);
  1551.             while (!feof(fApp))
  1552.             {
  1553.                 line++;
  1554.                 if(found == line)
  1555.                 {
  1556.                     fputs(buff,fTemp);
  1557.                     fgets(buff,512,fApp); // store current line into buffer2
  1558.                 }
  1559.                 else
  1560.                 {
  1561.                     fgets(buff2,512,fApp);
  1562.                     fputs(buff2,fTemp);
  1563.                 }
  1564.             }
  1565.             fclose(fApp);
  1566.             fclose(fTemp);
  1567.             rename("editApp.txt","APP.txt");
  1568.         }
  1569.         else
  1570.         {
  1571.             printf("SEE YOU AGAIN!");
  1572.             return;
  1573.             system("pause");
  1574.  
  1575.         }
  1576.     }
  1577.     else
  1578.     {
  1579.         printf("\n\nID NOT DETECTED\n!");
  1580.     }
  1581.     system("pause");
  1582. }
  1583.  
  1584.  
  1585. void deleteApp()
  1586. {
  1587.     system("cls");
  1588.     FILE *fApp;
  1589.     FILE *fpatient;
  1590.     fApp = fopen("APP.txt","r");
  1591.     char buffer[1024]=" ";
  1592.     char s[4] = "-->";
  1593.     char *token;
  1594.     int counter = 1;
  1595.     char tempID[100];
  1596.     if(fApp==NULL)
  1597.     {
  1598.         printf("FILE CANNOT BE OPENED!\n");
  1599.         exit(1);
  1600.     }
  1601.     else
  1602.     {
  1603.         char selection;
  1604.         printf("ENTER ID: ");
  1605.         fflush(stdin);
  1606.         gets(tempID);
  1607.  
  1608.         while(fgets(buffer,1024,fApp) != NULL)
  1609.         {
  1610.             token = strtok(buffer, s);
  1611.             if ( strcmp(token,tempID)== 0)
  1612.             {
  1613.                 strcpy(appdets.pid,token);
  1614.                 token = strtok(NULL,s);
  1615.                 strcpy(appdets.date,token);
  1616.                 token = strtok(NULL,s);
  1617.                 strcpy(appdets.time,token);
  1618.                 token = strtok(NULL,s);
  1619.                 strcpy(appdets.location,token);
  1620.                 token = strtok(NULL,s);
  1621.                 strcpy(appdets.doctor,token);
  1622.                 token = strtok(NULL,s);
  1623.                 strcpy(appdets.apptype,token);
  1624.                 token = strtok(NULL,s);
  1625.  
  1626.  
  1627.                 printf("Patient's ID:           %s\n",appdets.pid);
  1628.                 printf("Appointment's Date:     %s\n",appdets.date);
  1629.                 printf("Appointment's Time:     %s\n",appdets.time);
  1630.                 printf("Appointment's Location: %s\n",appdets.location);
  1631.                 printf("Doctor In Charge:       %s\n",appdets.doctor);
  1632.                 printf("Appointment's Type:     %s\n",appdets.apptype);
  1633.                 printf("------------------------------------------------------\n");
  1634.                 printf("Are you sure you wanted to delete this entry?\n");
  1635.                 fflush(stdin);
  1636.                 printf("CHOICE:");
  1637.                 selection=getchar();
  1638.                 if(toupper(selection)=='Y')
  1639.                 {
  1640.                     char words[100];
  1641.                     char *buffer;
  1642.                     char *ptr;
  1643.                     int  read_line=0;
  1644.                     char user_input[100];
  1645.                     int  done=0;
  1646.  
  1647.                     buffer=(char *)malloc(1000*sizeof(char));
  1648.                     memset(buffer,0,1000*sizeof(char));
  1649.                     ptr=buffer;
  1650.  
  1651.                     strcat(appdets.pid,"\n");
  1652.  
  1653.                     while(fgets(words,100,fApp) != NULL)
  1654.                     {
  1655.                         read_line ++;
  1656.                         if(read_line != 0)
  1657.                         {
  1658.                             strcpy(ptr,words);
  1659.                             ptr +=strlen(words);
  1660.                         }
  1661.                     }
  1662.                     fclose(fApp);
  1663.  
  1664.                     fpatient=fopen("APP.txt","w");
  1665.                     fprintf(fApp,"%s",buffer);
  1666.                     fclose(fApp);
  1667.                 }
  1668.             }
  1669.         }
  1670.     }
  1671. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement