Case study 8 – Develop a Hospital Management System Write C programs to
- Store the patient details in to a text file.
- View the details of patients using phone number, NIC , etc…
- Store the patient channeling details to another text file.
- Display the summary of the patients. create 4 seperate c programs covering all sections.
Can someone please help me because I don't get an output for section 2 and 4. section 1 and 3 works fine. All for sections are interconnected I guess.
**This is the code I created for section 1:
#include<stdio.h>
int main(void)
{
int pnum,age,cnum,nic;
char name[20],gender[6],address[50];
FILE * fp;
fp = fopen("patient.txt", "a");
printf("Add patient details\n\n");
printf("Patient number: ");
scanf("%d", &pnum);
printf("First name: ");
scanf(" %s", &name);
printf("Gender: ");
scanf(" %s", &gender);
printf("Age: ");
scanf("%d", &age);
printf("Address: ");
scanf(" %s", &address);
printf("NIC: ");
scanf("%d", &nic);
printf("Contact number: ");
scanf("%d", &cnum);
fprintf(fp, "%d %s %s %d %s %d %d\n", pnum, name, gender, age, address, nic, cnum);
fclose(fp);
return 0;
}
**This is the code I created for section 2:
#include<stdio.h>
int main(void)
{
int pnum,age,cnum,nic;
char name[20],gender[6],address[50];
FILE * fp;
fp = fopen("patient.txt", "r");
if ( fp != NULL)
{
while(!feof(fp))
{
fscanf(fp, "%d %s %s %d %s %d %d", pnum, name, gender, age, address, nic, cnum);
printf("%d %s %s %d %s %d %d", pnum, name, gender, age, address, nic, cnum);
}
fclose(fp);
}
else
{
printf("could not open file\n");
}
return 0;
}
**This is the code for section 3:
#include <stdio.h>
int main(void)
{
int pnum,chnum,nic;
char name[20],doc[20],sickness[50];
FILE * fp1;
fp1 = fopen("channeling.txt", "a");
printf("Add patient channeling details\n\n");
printf("Patient number: ");
scanf("%d", &pnum);
printf("Channeling number: ");
scanf("%d", &chnum);
printf("First name: ");
scanf(" %s", &name);
printf("NIC: ");
scanf("%d", &nic);
printf("Sickness: ");
scanf(" %s", &sickness);
printf("Prescribed doctor: ");
scanf(" %s", &doc);
fprintf(fp1, " %d %d %s %d %s %s\n", pnum, chnum, name, nic, sickness, doc);
fclose(fp1);
return 0;
}
**This is the code for section 4:
#include<stdio.h>
int main(void)
{
int pnum,age,cnum,nic;
char name[20],gender[6],address[50];
FILE * fp;
fp = fopen("patient.txt", "r");
if ( fp != NULL)
{
while(!feof(fp))
{
fscanf(fp, "%d %s %s %d %s %d %d", pnum, name, gender, age, address, nic, cnum);
printf("%d %s %s %d %s %d %d", pnum, name, gender, age, address, nic, cnum);
}
fclose(fp);
}
else
{
printf("could not open file\n");
}
return 0;
}