Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-------------------------------Include Header-------------------------------*/
- #define _CRT_SECURE_NO_WARNINGS
- #include<stdio.h> //Include the Standard Input/Output Header
- #include<string.h> //Include the Strings Header
- #include<ctype.h> //Include the Header to handle Characters
- #include<windows.h>
- #include<stdlib.h> //Include the Standard Library Header
- /*-----------------------------Sub function declaration------------------------*/
- //int or void is return type
- //Login function
- int doc(); //function header of "doctor"
- int rec(); //function header of "reception"
- //Selection menu
- void doc_menu();
- void rec_menu();
- void doc_pat_menu();
- void doc_app_menu();
- void rec_pat_menu();
- void rec_app_menu();
- //Add function
- int add_new_pat();
- int add_app();
- //View and Search function
- void view_pat();
- void search_pat();
- void view_app();
- void search_app();
- //Delete and Modify function
- void delete_pat();
- void delete_app();
- void modify_pat();
- void modify_app();
- //Search function
- int find_pat();
- int find_app();
- //global variable to call for each choice needed
- int choice;
- //Validation Function
- int num_str_validation();
- int alpha_validation();
- void gotoxy();
- fpos_t position;
- //Structure for patient
- struct patient
- {
- char pat_name[25];
- char pat_ID[5];
- char gender[5];
- char age[5];
- char contact_num[13];
- char ic_num[15];
- char app_type[20];
- char doc_name[25];
- char app_date[10];
- char app_time[5];
- char room[10];
- }p1;
- int alpha_str_validation(char input[])
- {
- int validation, i;
- for(i=0;i<(strlen(input));i++)
- {
- if(isalpha(input[i])||(isspace(input[i])))
- validation=1;
- else
- {
- validation=0;
- break;
- }
- }
- return validation;
- }
- int num_str_validation(char input[])
- {
- int validation, i;
- for(i=0;i<(strlen(input));i++)
- {
- if(input[i]>=48 && input[i]<=57)
- validation=1;
- else
- {
- validation=0;
- break;
- }
- }
- return validation;
- }
- void getPatientName()
- {
- int n=0;
- int validation=0;
- char buffer[100];
- do
- {
- printf("Enter Name\t\t:");
- gets(buffer);
- while(n < sizeof(buffer))
- {
- if(buffer[n] == ' ')
- buffer[n] = '_' ;
- n++ ;
- }
- buffer[n] = '0';
- strcpy(p1.pat_name , buffer);
- validation = alpha_str_validation(p1.pat_name);
- }
- while(validation == 0);
- }
- void getPatientID()
- {
- int validation = 0;
- do
- {
- printf("Enter Patient ID\t:");
- gets(p1.pat_ID);
- validation = num_str_validation(p1.pat_ID);
- }
- while(validation ==0);
- }
- void getGender()
- {
- printf("Enter Gender\t\t:");
- gets(p1.gender);
- }
- void getAge()
- {
- printf("Enter Age\t\t:");
- gets(p1.age);
- }
- void getContactNum()
- {
- printf("Enter Contact Number\t:");
- gets(p1.contact_num);
- }
- void getIcNum()
- {
- printf("Enter IC Number\t\t:");
- gets(p1.ic_num);
- }
- void getAppType()
- {
- gotoxy(25,10);
- printf("Enter Appointment Type\t:");
- gets(p1.app_type);
- }
- void getDocName()
- {
- gotoxy(25,11);
- printf("Enter Doctor Name\t:");
- gets(p1.doc_name);
- }
- void getAppDate()
- {
- gotoxy(25,12);
- printf("Enter Date\t\t:");
- gets(p1.app_date);
- }
- void getAppTime()
- {
- gotoxy(25,13);
- printf("Enter Appointment Time\t:");
- gets(p1.app_time);
- }
- void getRoom()
- {
- gotoxy(25,14);
- printf("Enter Room\t\t:");
- gets(p1.room);
- }
- //function below allow the implementation of gotoxy in codeblocks
- COORD coord = { 0, 0 };
- void gotoxy(int x, int y)
- {
- coord.X = x;
- coord.Y = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- int find_pat(FILE *fp)
- {
- const char s[2] = ">";
- char *token;
- char confirm;
- fp = fopen("patient.txt", "r");
- if(fp==NULL)
- {
- exit(1);
- printf("File cannot open");
- }
- else
- {
- char buffer[200];
- char input[200];
- char tok[200];
- int found = 1;
- int save =0 , line=0 , count=1;
- system("cls");
- printf("Enter the Patient ID: ");
- fflush(stdin);
- gets(input);
- rewind(fp);
- while(fgets(buffer,200,fp) != NULL)
- {
- line ++;
- token = strtok(buffer, s);
- if(strcmp(token,input)==0)
- {
- save = line ;
- break;
- }
- }
- if(save != 0)
- {
- rewind(fp);
- while(count<=save)
- {
- fscanf(fp,"%s %s %s %s %s %s",p1.pat_ID,p1.pat_name,p1.gender,p1.age,p1.contact_num,p1.ic_num);
- if(count!=save)
- {
- count++;
- }
- else
- {
- p1.pat_ID[strlen(p1.pat_ID)-1] = '\0'; //delete '>' in the file
- printf("\nPatient ID\t: %s\n",p1.pat_ID);
- printf("Patient Name\t: %s\n",p1.pat_name);
- printf("Gender\t\t: %s\n",p1.gender);
- printf("Age\t\t: %s\n",p1.age);
- printf("Contact number\t: %s\n",p1.contact_num);
- printf("IC number\t: %s\n\n",p1.ic_num);
- return count;
- }
- }
- }
- else
- {
- printf("\nID not found\n");
- return -1 ;
- }
- }
- fclose(fp);
- system("pause");
- }
- int find_app(FILE *fp1)
- {
- const char s[2] = ">";
- char *token;
- char confirm;
- fp1 = fopen("appointment.txt", "r");
- if(fp1==NULL)
- {
- exit(1);
- printf("File cannot open");
- }
- else
- {
- char buffer[200];
- char input[200];
- char tok[200];
- int found = 1;
- int save =0 , line=0 , count=1;
- system("cls");
- printf("Enter the Patient ID: ");
- fflush(stdin);
- gets(input);
- rewind(fp1);
- while(fgets(buffer,200,fp1) != NULL)
- {
- line ++;
- token = strtok(buffer, s);
- if(strcmp(token,input)==0)
- {
- save = line ;
- break;
- }
- }
- if(save != 0)
- {
- rewind(fp1);
- while(count<=save)
- {
- fscanf(fp1,"%s %s %s %s %s %s %s",p1.pat_ID,p1.pat_name,p1.app_type,p1.doc_name,p1.app_date,p1.app_time,p1.room);
- if(count!=save)
- {
- printf("Test");
- count++;
- }
- else
- {
- p1.pat_ID[strlen(p1.pat_ID)-1] = '\0'; //delete '>' in the file
- printf("Patient ID: %s\n",p1.pat_ID);
- printf("Patient Name: %s\n",p1.pat_name);
- printf("Appointment Type: %s\n",p1.app_type);
- printf("Doctor Name: %s\n",p1.doc_name);
- printf("Date: %s\n",p1.app_date);
- printf("Time: %s\n",p1.app_time);
- printf("Room: %s\n",p1.room);
- return count;
- }
- }
- }
- else
- {
- printf("\nID not found\n");
- return -1 ;
- }
- }
- fclose(fp1);
- system("pause");
- }
- /*------------------------Main------------------------*/
- void main()
- {
- int a, b;
- do
- {
- system("cls");
- gotoxy(21,7);
- printf("********** Welcome to Jack Hospital **********");
- gotoxy(33, 11);
- printf("1. Doctor\n");
- gotoxy(33, 12);
- printf("2. Reception\n");
- gotoxy(33, 14);
- printf("Enter your choice:");
- scanf("%d", &choice);
- if (choice < 1 || choice > 2)
- {
- gotoxy(25, 16);
- printf("Invalid Entry\n");
- gotoxy(25, 17);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: a = doc();
- if (a != 0)
- doc_menu();
- break;
- case 2: b = rec();
- if (b != 0)
- rec_menu();
- break;
- }
- }
- while (choice <1 || choice > 2);
- }
- /*--------------------Login Function------------------------*/
- //Doctor Login Process
- int doc()
- {
- char name[30] = "Doctor", password[10] = "1234";
- char user_input[30], user_password[10];
- int a = 0;
- do
- {
- system("cls");
- gotoxy(22, 8);
- printf("********** Welcome Doctor **********\n");
- fflush(stdin);
- gotoxy(25, 11);
- printf("User Name\t:");
- gets(user_input);
- fflush(stdin);
- gotoxy(25, 13);
- printf("Password\t:");
- gets(user_password);
- if ((strcmp(name, user_input) == 0) && (strcmp(password, user_password) == 0))
- {
- printf("Login successful");
- a = 1;
- }
- else
- {
- a = 0;
- }
- }
- while (a == 0);
- return a;
- }
- //Reception Login Process
- int rec()
- {
- char name[30] = "Jack", password[10] = "1234";
- char user_input[30], user_password[10];
- int a = 0;
- do
- {
- system("cls");
- gotoxy(22, 8);
- printf("********** Welcome Admin ***********\n");
- fflush(stdin);
- gotoxy(25, 11);
- printf("User Name\t:");
- fflush(stdin);
- gets(user_input);
- gotoxy(25, 13);
- printf("Password\t:");
- gets(user_password);
- if ((strcmp(name, user_input) == 0) && ((strcmp(password, user_password) == 0)))
- {
- printf("Login successful");
- a = 1;
- }
- else
- {
- a = 0;
- }
- }
- while (a == 0);
- return a;
- }
- /*---------------------------Doctor Menu----------------------------*/
- void doc_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- gotoxy(25, 8);
- printf("----------Doctor Menu----------");
- gotoxy(25, 10);
- printf("1. Patient\n");
- gotoxy(25, 11);
- printf("2. Appointment\n");
- gotoxy(25, 12);
- printf("3. Logout");
- gotoxy(25, 13);
- printf("4. Exit");
- if (choice < 1 && choice > 4)
- {
- gotoxy(25, 16);
- printf("Invalid Entry\n");
- gotoxy(25, 17);
- printf("Please try again!\n");
- }
- gotoxy(25, 15);
- printf("Enter your choice:");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1: doc_pat_menu();
- break;
- case 2: doc_app_menu();
- break;
- case 3: return;
- case 4: exit(0);
- }
- }
- }
- while (choice <1 || choice > 4);
- }
- /*--------------------------Reception Menu---------------------------*/
- void rec_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- gotoxy(25, 8);
- printf("----------Reception Menu----------");
- gotoxy(25, 10);
- printf("1. Patient\n");
- gotoxy(25, 11);
- printf("2. Appointment\n");
- gotoxy(25, 12);
- printf("3. Logout");
- gotoxy(25, 13);
- printf("4. Exit");
- gotoxy(25, 14);
- printf("Enter your choice:");
- scanf("%d", &choice);
- if (choice < 1 || choice > 2)
- {
- gotoxy(25, 16);
- printf("Invalid Entry\n");
- gotoxy(25, 17);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: rec_pat_menu();
- break;
- case 2: rec_app_menu();
- break;
- case 3: return;
- case 4: exit(0);
- }
- }
- }
- while (choice <1 || choice > 2);
- }
- void doc_pat_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- gotoxy(25, 10);
- printf("1. Search Patient\n");
- gotoxy(25, 11);
- printf("2. View Patient\n");
- gotoxy(25, 12);
- printf("3. Back\n");
- gotoxy(25, 14);
- printf("Enter your choice:");
- scanf("%d", &choice);
- if ((choice <1 || choice > 2))
- {
- gotoxy(25, 16);
- printf("Invalid Entry\n");
- gotoxy(25, 17);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: search_pat();
- break;
- case 2: view_pat();
- break;
- case 3: return;
- }
- }
- }
- while (choice <1 || choice > 2);
- }
- void doc_app_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- gotoxy(25, 10);
- printf("1. Search Appointment\n");
- gotoxy(25, 11);
- printf("2. View Appointment\n");
- gotoxy(25, 12);
- printf("3. Back\n");
- gotoxy(25, 14);
- printf("Enter your choice:");
- scanf("%d", &choice);
- if (choice <1 || choice > 2)
- {
- gotoxy(25, 16);
- printf("Invalid Entry\n");
- gotoxy(25, 17);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: search_app();
- break;
- case 2: view_app();
- break;
- case 3: return;
- }
- }
- }
- while (choice <1 || choice > 2);
- }
- void rec_pat_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- gotoxy(25, 8);
- printf("1. Add New Patient\n");
- gotoxy(25, 9);
- printf("2. View Patient\n");
- gotoxy(25, 10);
- printf("3. Search Patient\n");
- gotoxy(25, 11);
- printf("4. Delete Patient\n");
- gotoxy(25, 12);
- printf("5. Modify Patient\n");
- gotoxy(25, 13);
- printf("6. Back\n");
- gotoxy(25, 15);
- printf("Enter your choice:");
- fflush(stdin);
- scanf("%d", &choice);
- if ((choice <1 || choice > 5))
- {
- gotoxy(25, 17);
- printf("Invalid Entry\n");
- gotoxy(25, 18);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: add_new_pat();
- break;
- case 2: view_pat();
- break;
- case 3: search_pat();
- break;
- case 4: delete_pat();
- break;
- case 5: modify_pat();
- break;
- case 6: return;
- }
- }
- }
- while ((choice <1 || choice > 5));
- }
- void rec_app_menu()
- {
- do
- {
- while(1)
- {
- system("cls");
- gotoxy(25, 8);
- printf("1. Add New Appointment\n");
- gotoxy(25, 9);
- printf("2. View Appointment\n");
- gotoxy(25, 10);
- printf("3. Search Appointment\n");
- gotoxy(25, 11);
- printf("4. Delete Appointment\n");
- gotoxy(25, 12);
- printf("5. Modify Appointment\n");
- gotoxy(25 ,13);
- printf("6. Back\n");
- gotoxy(25, 15);
- printf("Enter your choice:");
- fflush(stdin);
- scanf("%d", &choice);
- if ((choice <1 || choice > 6))
- {
- gotoxy(25, 16);
- printf("Invalid Entry\n");
- gotoxy(25, 17);
- printf("Please try again!\n");
- }
- switch (choice)
- {
- case 1: add_app();
- break;
- case 2: view_app();
- break;
- case 3: search_app();
- break;
- case 4: delete_app();
- break;
- case 5: modify_app();
- break;
- case 6: return;
- }
- }
- }
- while ((choice <1 || choice > 6));
- }
- //Add new patient
- int add_new_pat() // Store patient details
- {
- char selection = 'Y';
- FILE*fp;
- fp = fopen("patient.txt", "a");
- while (selection = 'Y')
- {
- system("cls");
- fflush(stdin);
- getPatientName();
- getPatientID();
- getGender();
- getAge();
- getContactNum();
- getIcNum();
- fprintf(fp, "%s>\t\t%s\t%s\t%s\t%s\t%s\n", p1.pat_ID, p1.pat_name, p1.gender, p1.age, p1.contact_num, p1.ic_num);
- printf("\nDo You Want To Add Another Patient's Details? (Y/N):");
- fflush(stdin);
- selection = getchar();
- if (toupper(selection) != 'Y')
- {
- fclose(fp);
- rec_pat_menu();
- }
- }
- }
- //View all patient details
- void view_pat()
- {
- int length = 0;
- FILE*fp;
- fp = fopen("patient.txt", "r");
- system("cls");
- if (fp == NULL)
- {
- printf("File Cannot Open!\n");
- system("pause");
- rec_pat_menu();
- }
- else
- {
- while (1)
- {
- fscanf(fp, "%s", p1.pat_ID);
- if(feof(fp))
- break;
- length = strlen(p1.pat_ID);
- p1.pat_ID[length - 1] = '\0';
- printf("Patient ID\t:%s\n", p1.pat_ID);
- fscanf(fp, "%s", p1.pat_name);
- printf("Patient Name\t:%s\n", p1.pat_name);
- fscanf(fp, "%s", p1.gender);
- printf("Gender\t\t:%s\n", p1.gender);
- fscanf(fp, "%s", p1.age);
- printf("Age\t\t:%s\n", p1.age);
- fscanf(fp, "%s", p1.contact_num);
- printf("Contact Number\t:%s\n", p1.contact_num);
- fscanf(fp, "%s", p1.ic_num);
- printf("IC Number\t:%s\n\n", p1.ic_num);
- };
- fclose(fp);
- system("pause");
- return;
- }
- }
- //Search patient
- void search_pat()
- {
- int check=0;
- FILE*fp;
- fp = fopen("patient.txt", "r");
- if(fp==NULL)
- {
- printf("Error");
- exit(1);
- }
- else
- {
- char cont = 'n';
- do
- {
- check = find_pat(fp);
- printf("Do you want to search another patient? (Y/N):");
- scanf("%c",&cont);
- }
- while(cont == 'y' || cont == 'Y');
- }
- fclose(fp);
- system("pause");
- return;
- }
- //Delete patient
- void delete_pat()
- {
- FILE *fp;
- fp = fopen("patient.txt", "r");
- if(fp==NULL)
- {
- printf("Error!");
- exit(1);
- }
- else
- {
- char confirm;
- int line=0;
- line = find_pat(fp);
- rewind(fp);
- if(line != -1)
- {
- printf("\nConfirm Delete? (Y/N):");
- confirm = getchar();
- if(confirm == 'Y' || confirm == 'y')
- {
- char words[100];
- char *buffer;
- char *ptr;
- int read_line = 0;
- char user_input[100];
- int done =0;
- buffer=(char *)malloc(1000*sizeof(char));
- memset(buffer,0,1000*sizeof(char));
- ptr=buffer;
- strcat(p1.pat_ID,"\n");
- while(fgets(words, 100, fp) != NULL)
- {
- read_line ++;
- if(read_line != line)
- {
- strcpy(ptr, words);
- ptr +=strlen(words);
- }
- }
- fclose(fp);
- fp=fopen("patient.txt","w");
- fprintf(fp, "%s", buffer);
- fclose(fp);
- }
- }
- }
- system("pause");
- }
- //Modify patient
- void modify_pat()
- {
- FILE *fp;
- fp = fopen("patient.txt", "r");
- if(fp==NULL)
- {
- exit(1);
- printf("File cannot open");
- }
- else
- {
- char confirm;
- int line=0;
- line = find_pat(fp);
- rewind(fp);
- if(line != -1)
- {
- printf("\nConfirm Edit?(Y/N):");
- confirm = getchar();
- if(confirm == 'Y' || confirm == 'y')
- {
- char words[1024];
- char *buffer;
- char *ptr;
- int read_line = 0;
- int done =0;
- buffer=(char *)malloc(1000*sizeof(char));
- memset(buffer,0,1000*sizeof(char));
- ptr=buffer;
- strcat(p1.pat_ID,"\n");
- while(fgets(words, 1024, fp) != NULL)
- {
- read_line ++;
- if(read_line != line)
- {
- strcpy(ptr, words);
- ptr +=strlen(words);
- }
- else if(read_line == line)
- {
- char newline[1024];
- system("cls");
- fflush(stdin);
- getPatientName();
- getPatientID();
- getGender();
- getAge();
- getContactNum();
- getIcNum();
- strcpy(newline,p1.pat_ID);
- strcat(newline,">");
- strcat(newline,"\t");
- strcat(newline,"\t");
- strcat(newline,p1.pat_name);
- strcat(newline,"\t");
- strcat(newline,p1.gender);
- strcat(newline,"\t");
- strcat(newline,p1.age);
- strcat(newline,"\t");
- strcat(newline,p1.contact_num);
- strcat(newline,"\t");
- strcat(newline,p1.ic_num);
- strcat(newline,"\n");
- strcpy(ptr, newline);
- ptr +=strlen(newline);
- printf("Modify is completed.");
- }
- }
- fclose(fp);
- fp=fopen("patient.txt","w");
- fprintf(fp, "%s", buffer);
- fclose(fp);
- }
- }
- }
- system("pause");
- }
- //Add appointment
- int add_app()
- {
- int line = 0;
- FILE*fp;
- FILE*fp1;
- fp=fopen("patient.txt","r");
- if(fp=NULL)
- {
- printf("Error!");
- exit(1);
- }
- else
- {
- line = find_pat(fp);
- char cont = 'Y';
- do
- {
- if(line != -1)
- {
- fp1=fopen("appointment.txt","a");
- char cont = 'y';
- fflush(stdin);
- getAppType();
- getDocName();
- getAppDate();
- getAppTime();
- getRoom();
- printf("Patient Name: %s",p1.pat_name);
- printf("Patient ID: %s", p1.pat_ID);
- printf("Appointment Type: %s",p1.app_type);
- printf("Doctor Name: %s",p1.doc_name);
- printf("Appointment Date: %s",p1.app_date);
- printf("Appointment Time: %s",p1.app_time);
- printf("Room: %s",p1.room);
- printf("Confirm Add?\n");
- if(cont == 'y' || cont == 'Y')
- {
- fprintf(fp1, "%s>\t%s\t\t%s\t%s\t%s\t%s\t%s\n",p1.pat_ID,p1.pat_name,p1.app_type, p1.doc_name, p1.app_date, p1.app_time, p1.room);
- }
- fclose(fp1);
- return 0;
- }
- else
- {
- printf("ID not detected\n");
- system("pause");
- return;
- }
- }
- while(cont == 'y' || cont == 'Y');
- }
- return -1;
- }
- //View all appointment details
- void view_app()
- {
- int length = 0;
- FILE*fp1;
- system("cls");
- fp1 = fopen("appointment.txt", "r");
- if (fp1 == NULL)
- {
- printf("File Cannot Open!\n");
- system("pause");
- rec_app_menu();
- }
- else
- {
- while (1)
- {
- fscanf(fp1, "%s", p1.pat_ID);
- if(feof(fp1))
- break;
- length = strlen(p1.pat_ID);
- p1.pat_ID[length - 1] = '\0';
- printf("Patient ID\t\t:%s\n", p1.pat_ID);
- fscanf(fp1, "%s", p1.pat_name);
- printf("Patient Name\t\t:%s\n", p1.pat_name);
- fscanf(fp1, "%s", p1.app_type);
- printf("Appointment Type\t:%s\n", p1.app_type);
- fscanf(fp1, "%s", p1.doc_name);
- printf("Doctor Name\t\t:%s\n", p1.doc_name);
- fscanf(fp1, "%s", p1.app_date);
- printf("Date\t\t\t:%s\n", p1.app_date);
- fscanf(fp1, "%s", p1.app_time);
- printf("Time\t\t\t:%s\n", p1.app_time);
- fscanf(fp1,"%s",p1.room);
- printf("Room\t\t\t:%s\n\n",p1.room);
- } ;
- fclose(fp1);
- system("pause");
- return;
- }
- }
- //Search appointment
- void search_app()
- {
- FILE*fp1;
- int check = 0;
- fp1 = fopen("appointment.txt", "r");
- if(fp1==NULL)
- {
- printf("Error");
- exit(1);
- }
- else
- {
- char cont = 'n';
- do
- {
- check = find_app(fp1);
- printf("Do you want to search again? (Y/N): ");
- scanf("%c",&cont);
- }
- while(cont == 'y' || cont == 'Y');
- }
- fclose(fp1);
- system("pause");
- return;
- }
- //delete appointment
- void delete_app()
- {
- FILE *fp1;
- fp1 = fopen("appointment.txt", "r");
- if(fp1==NULL)
- {
- printf("Error!");
- exit(1);
- }
- else
- {
- char confirm;
- int line=0;
- line = find_app(fp1);
- rewind(fp1);
- if(line != -1)
- {
- printf("\nConfirm Delete?");
- confirm = getchar();
- if(confirm == 'Y' || confirm == 'y')
- {
- char words[100];
- char *buffer;
- char *ptr;
- int read_line = 0;
- char user_input[100];
- int done =0;
- buffer=(char *)malloc(1000*sizeof(char));
- memset(buffer,0,1000*sizeof(char));
- ptr=buffer;
- strcat(p1.pat_ID,"\n");
- while(fgets(words, 100, fp1) != NULL)
- {
- read_line ++;
- if(read_line != line)
- {
- strcpy(ptr, words);
- ptr +=strlen(words);
- }
- }
- fclose(fp1);
- fp1=fopen("appointment.txt","w");
- fprintf(fp1, "%s", buffer);
- fclose(fp1);
- }
- }
- }
- system("pause");
- }
- //Modify appointment
- void modify_app()
- {
- FILE *fp1;
- fp1 = fopen("appointment.txt", "r");
- if(fp1==NULL)
- {
- exit(1);
- printf("File cannot open");
- }
- else
- {
- char confirm;
- int line=0;
- line = find_app(fp1);
- rewind(fp1);
- if(line != -1)
- {
- printf("\nConfirm Edit?");
- confirm = getchar();
- if(confirm == 'Y' || confirm == 'y')
- {
- char words[1024];
- char *buffer;
- char *ptr;
- int read_line = 0;
- int done =0;
- buffer=(char *)malloc(1000*sizeof(char));
- memset(buffer,0,1000*sizeof(char));
- ptr=buffer;
- strcat(p1.pat_ID,"\n");
- while(fgets(words, 1024, fp1) != NULL)
- {
- read_line ++;
- if(read_line != line)
- {
- strcpy(ptr, words);
- ptr +=strlen(words);
- }
- else if(read_line == line)
- {
- char newline[1024];
- system("cls");
- fflush(stdin);
- getPatientName();
- getPatientID();
- getAppType();
- getDocName();
- getAppDate();
- getAppTime();
- getRoom();
- strcpy(newline,p1.pat_ID);
- strcat(newline,">");
- strcat(newline,"\t");
- strcat(newline,"\t");
- strcat(newline,p1.pat_name);
- strcat(newline,"\t");
- strcat(newline,p1.app_type);
- strcat(newline,"\t");
- strcat(newline,p1.doc_name);
- strcat(newline,"\t");
- strcat(newline,p1.app_date);
- strcat(newline,"\t");
- strcat(newline,p1.app_time);
- strcat(newline,"\t");
- strcat(newline,p1.room);
- strcat(newline,"\n");
- strcpy(ptr, newline);
- ptr +=strlen(newline);
- printf("Modify is completed.");
- }
- }
- fclose(fp1);
- fp1=fopen("appointment.txt","w");
- fprintf(fp1, "%s", buffer);
- fclose(fp1);
- }
- }
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement