Training
Training
#include<stdlib.h>
#include<time.h>
struct patient{
int id;
char patientName[50];
char patientAddress[50];
char disease[50];
char date[12];
}p;
struct doctor{
int id;
char name[50];
char address[50];
char specialize[50];
char date[12];
}d;
FILE *fp;
int main(){
int ch;
while(1){
system("cls");
printf("2.Patient List\n");
printf("3.Discharge Patient\n");
printf("4.Add Doctor\n");
printf("5.Doctors List\n");
printf("0.Exit\n\n");
scanf("%d", &ch);
switch(ch){
case 0:
exit(0);
case 1:
admitPatient();
break;
case 2:
patientList();
break;
case 3:
dischargePatient();
break;
case 4:
addDoctor();
break;
case 5:
doctorList();
break;
default:
printf("Invalid Choice...\n\n");
getch();
return 0;
void admitPatient(){
char myDate[12];
time_t t = time(NULL);
struct tm tm = *localtime(&t);
strcpy(p.date, myDate);
fp = fopen("patient.txt", "ab");
scanf("%d", &p.id);
fflush(stdin);
gets(p.patientName);
fflush(stdin);
gets(p.patientAddress);
fflush(stdin);
gets(p.disease);
fclose(fp);
void patientList(){
system("cls");
printf("%-10s %-30s %-30s %-20s %s\n", "Id", "Patient Name", "Address", "Disease", "Date");
printf("----------------------------------------------------------------------------------------------------------\n");
fp = fopen("patient.txt", "rb");
fclose(fp);
void dischargePatient(){
scanf("%d", &id);
FILE *ft;
fp = fopen("patient.txt", "rb");
ft = fopen("temp.txt", "wb");
if(id == p.id){
f=1;
}else{
if(f==1){
}else{
fclose(fp);
fclose(ft);
remove("patient.txt");
rename("temp.txt", "patient.txt");
}
void addDoctor(){
char myDate[12];
time_t t = time(NULL);
struct tm tm = *localtime(&t);
strcpy(d.date, myDate);
int f=0;
system("cls");
fp = fopen("doctor.txt", "ab");
scanf("%d", &d.id);
fflush(stdin);
gets(d.name);
fflush(stdin);
gets(d.address);
fflush(stdin);
gets(d.specialize);
printf("Doctor Added Successfully\n\n");
fclose(fp);
void doctorList(){
system("cls");
printf("-------------------------------------------------------------------------------------------------------------------\n");
fp = fopen("doctor.txt", "rb");
printf("%-10d %-30s %-30s %-30s %s\n", d.id, d.name, d.address, d.specialize, d.date);
fclose(fp);
}
OUTPUT: