Advertisement
Guest User

ASD

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