Simple Hospital Management System In C With Source Code
The Simple Hospital Management System In C is being develop in C programming language, This Hospital Management System C Program is based on the concept of managing a patient’s record of a hospital. There’s no login system available for this system, the user can freely use its feature.
A Simple C Program For Hospital Management System creates an external file to store the user’s data permanently. Talking about the features of this Hospital Management System In C, the user can perform the CRUD operations to it. Like, add patient details by entering his/her name, disease name, phone number, cabin number, etc. The user can also view all the available patient records. Such as details and search a patient by its name, age, disease, cabin number. Besides, the user can edit information as well as remove a patient’s whole date or only his/her name, phone number, disease name, cabin number.
This Hospital Management System In C Language also includes a downloadable Hospital Management System Code for free, just find the downloadable source code below and click to start downloading.
To start creating a Simple Hospital Management System In C , make sure that you have a Code Blocks or any platform of C installed in your computer.
ABOUT PROJECT | PROJECT DETAILS |
---|---|
Project Name : | Simple Hospital Management System |
Project Platform : | C/C++ |
Programming Language Used: | C Programming Language |
Developer Name : | itsourcecode.com |
IDE Tool (Recommended): | Dev-C++/Codeblocks |
Project Type : | Desktop Application |
Database: | Stores data in .DAT file |
Upload Date and Time: | September 18, 2020-6:56 am |
Steps on how to create a Hospital System In C
Time needed: 5 minutes.
Simple Hospital Management System In C With Source Code
- Step 1: Create a new project.
First open the code blocks IDE and click “create a new project“.
- Step 2: Choose console application.
Second click the “console application” and after that click “next“.
- Step 3: Choose C language.
Third choose “C language” and click “next“.
- Step 4: Name your project.
Fourth name the project you’ve created and click “next” after that click “finish“.
- Step 5: The actual code.
You are free to copy the given source code below or download the downloadable source code given.
The Code Given Below Is For Declaring Methods
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
struct ad { char name[30]; char disease[30]; int cabin,phone,age; } x[100]; int n,i,j=0,a=0,sum=0,g,flag,num; void read(); void add(); void view(); void search(); void edit(); void del(); void show(); |
The code given which is declaring the methods and variables to be call.
The Code Given Below Is For The Main Module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
int main() { read(); int c,i,q; printf("Simple Hospital Management System\n"); int m,n; //making out the pattern for(m=1; m<=4; m++) { for(n=1; n<=5; n++) printf(" "); for(n=1; n<=m-1; n++) { printf(" "); } for(n=1; n<=4-m+1; n++) { if(n==4-m+1 || m==1 || m==4) printf("*"); else printf(" "); } for(n=1; n<=4-m+1; n++) { if(n==1 ||m==1 || m==4) printf("*"); else printf(" "); } printf("\n"); } while(c!=6) { printf("**Enter your choice**\n\n1. Add Information\n2. View Information\n3. Search\n4. Edit Information\n5. Delete Information\n6. Exit\n\nOption="); scanf("%d",&c);//choice for option fflush(stdin);//making it clear if(c==1)//add { system("cls"); add(); } else if(c==2)//view { system("cls"); view(); } else if(c==3)//search { system("cls"); search(); } else if(c==4)//edit { system("cls"); edit(); } else if(c==5)//delete { system("cls"); del(); } else if(c==6) { write(); return 0; } else { system("cls"); printf("\n\nInvalid input , try again by using valid inputs"); } printf("\n\n"); } } |
In this module which is the main module of the system. (Simple Hospital Management System In C With Source Code)
The Code Given Below Is For The Adding Module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
void add() { printf("\n\n"); printf("Already data inputed on the database =%d\n\n",num);//how many inputs printf("How many entry do you want to add=\n"); scanf("%d",&n); sum=n+num; for(i=num,j=0; i<sum; i++) { printf("\n"); fflush(stdin); printf("Enter patient's Name = "); gets(x[i].name); fflush(stdin); printf("Enter disease = "); gets(x[i].disease); fflush(stdin); printf("Enter the age = "); scanf("%d",&x[i].age); fflush(stdin); printf("Enter cabin no = "); scanf("%d",&x[i].cabin); fflush(stdin); printf("Enter phone number = "); scanf("%d",&x[i].phone); fflush(stdin); printf("\n"); j++; a++; num++; } } |
In this module which is the adding module of the system.
The Code Given Below Is For The View Module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
void view() { for(i=0; i<num; i++) { printf("\n"); printf("Serial Number=%d\n",i); printf("Name = "); puts(x[i].name); printf("Disease = "); puts(x[i].disease); printf("Cabin no = %d\nPhone number = 0%d\nAge=%d",x[i].cabin,x[i].phone,x[i].age); printf("\n\n"); } } |
In this module which is the view module of the system.
The Code Given Below Is For The Module Edit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
void edit() { int q,p; fflush(stdin); printf("What do you want to edit ?\n"); printf("Enter your option\n"); printf("1.Name\n2.Disease\n3.Age\n4.Cabin\n5.Phone no.\n"); printf("Option="); scanf("%d",&q);//option if(q<=5) { printf("Enter the serial no of that patient= (0 - %d)=",num-1); scanf("%d",&p);//serial number if(p<num) { if(q==1) { fflush(stdin); printf("Enter the new name="); gets(x[p].name); } else if(q==2) { fflush(stdin); printf("Enter the new Disease="); gets(x[p].disease); } else if(q==3) { fflush(stdin); printf("Enter the new Age="); scanf("%d",&x[p].age); } else if(q==4) { fflush(stdin); printf("Enter the new Cabin no="); scanf("%d",&x[p].cabin); } else if(q==5) { fflush(stdin); printf("Enter the new Phone no ="); scanf("%d",&x[p].phone); } } else { printf("\n\nInvalid Serial \nTry Again !!\n\n"); } } else { printf("\n\nInvalid option\nTry Again!!\n\n"); } } |
In this module which is the module for editing the data in the system.
The Code Given Below Is For The Module Search
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
void search() { int s,h,f; char u[100]; printf("By what do you want to search ?\n"); printf("1.Serial no.\n2.Name\n3.Disease\n4.Cabin no.\n5.Phone no.\n6.Age\n\nOption = "); scanf("%d",&h); if(h==1) { printf("Enter Serial number of the patient="); scanf("%d",&s); if(s<num) { printf("\n"); printf("Serial Number=%d\n",s); printf("Name = "); puts(x[s].name); printf("Disease = "); puts(x[s].disease); printf("Cabin no = %d\nPhone number = 0%d\nAge = %d",x[s].cabin,x[s].phone,x[s].age); printf("\n\n"); } else printf("\n\nNot Found\n\n"); } else if(h==2)//problem is here......... { int f=1; fflush(stdin); printf("Enter your name="); gets(u); fflush(stdin); for(g=0; g<num; g++) { if(strcmp(u,x[g].name)==0) { printf("\n"); printf("Serial Number=%d\n",g); printf("Name = "); puts(x[g].name); printf("Disease = "); puts(x[g].disease); printf("Cabin no = %d\nPhone number = 0%d\nAge = %d",x[g].cabin,x[g].phone,x[g].age); printf("\n\n"); f=0; } } if(f==1) printf("\nNot Found\n"); } else if(h==3) { int f=1; fflush(stdin); printf("Enter Disease = "); gets(u); fflush(stdin); for(g=0; g<num; g++) { if(strcmp(u,x[g].disease)==0) { printf("\n"); printf("Serial Number=%d\n",g); printf("Name = "); puts(x[g].name); printf("Disease = "); puts(x[g].disease); printf("Cabin no = %d\nPhone number = 0%d\nAge = %d",x[g].cabin,x[g].phone,x[g].age); printf("\n\n"); f=0; } } if(f==1) printf("\nNot Found\n"); } else if(h==4) { int f=1; printf("Enter Cabin number = "); scanf("%d",&f); for(g=0; g<num; g++) { if(f==x[g].cabin) { printf("\n"); printf("Serial Number=%d\n",g); printf("Name = "); puts(x[g].name); printf("Disease = "); puts(x[g].disease); printf("Cabin no = %d\nPhone number = 0%d\nAge = %d",x[g].cabin,x[g].phone,x[g].age); printf("\n\n"); f=0; } } if(f==1) printf("Not Found\n\n"); } else if(h==5) { int f=1; printf("Enter Phone number = "); scanf("%d",&f); for(g=0; g<num; g++) { if(f==x[g].phone) { printf("\n"); printf("Serial Number=%d\n",g); printf("Name = "); puts(x[g].name); printf("Disease = "); puts(x[g].disease); printf("Cabin no = %d\nPhone number = 0%d\nAge = %d",x[g].cabin,x[g].phone,x[g].age); printf("\n\n"); f=0; } } if(f==1) printf("Not Found"); } else if(h==6) { int f=1; printf("Enter Age = "); scanf("%d",&f); for(g=0; g<num; g++) { if(f==x[g].age) { printf("\n"); printf("Serial Number=%d\n",g); printf("Name = "); puts(x[g].name); printf("Disease = "); puts(x[g].disease); printf("Cabin no = %d\nPhone number = 0%d\nAge = %d",x[g].cabin,x[g].phone,x[g].age); printf("\n\n"); f=0; } } if(f==1) printf("Not Found\n\n"); } else printf("\n\nInvalid input\n\n"); } |
In this module which is the search module of the system. (Simple Hospital Management System In C With Source Code)
The Code Given Below Is For The Module Delete
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
void del() { int f,h; printf("Enter the serial number of the patient that you want to delete="); scanf("%d",&f); if(f<num) { printf("What do you want ?\n"); printf("1.Remove the whole record\n2.Remove Name\n3.Remove Disease\n4.Remove age\n5.Remove Cabin\n6.Remove phone number\nOption = "); scanf("%d",&h); if(h==1) { while(f<num) { strcpy(x[f].name,x[f+1].name); strcpy(x[f].disease,x[f+1].disease); x[f].age=x[f+1].age; x[f].cabin=x[f+1].cabin; x[f].phone=x[f+1].phone; f++; } num--; } else if(h==2) { strcpy(x[f].name,"Cleared"); } else if(h==3) { strcpy(x[f].disease,"Cleared"); } else if(h==4) { x[f].age=0; } else if(h==5) { x[f].cabin=0; } else if(h==6) { x[f].phone=0; } } else printf("\n\nInvalid Serial number\n"); } |
In this module which is the delete module of the system.
The Code Given Below Is For The Module Reading The Data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
void read() { FILE *fp = fopen("patient.txt","r"); if(fp == NULL) { //create empty file, so that we can open it //in the next execution of this program fp = fopen("patient.txt","w"); fclose(fp); printf("File does not exist, I JUST CREATED IT, exiting...\n\n\n"); return 0; } num = fread(x, sizeof(struct ad),100, fp); fclose(fp); } |
In this module which is the module for reading the data or the information of the patient in the system.
The Code Given Below Is For The Module Write The Data
1 2 3 4 5 6 7 8 9 10 11 12 13 |
void write() { FILE *fp = fopen("patient.txt","w"); if(fp == NULL) { printf("Error"); exit(1); } fwrite(x, sizeof(struct ad),num, fp); fclose(fp); } |
In this module which is the module for writing the data or the information of the patient.
Output

Downloadable Source Code
About The Project
Its creates an external file to store the user’s data permanently. Talking about the features of this system, the user can perform the CRUD operations to it. Like, add patient details by entering his/her name, disease name, phone number, cabin number, etc.
The user can also view all the available patient records. Such as details and search a patient by its name, age, disease, cabin number. Besides, the user can edit information as well as remove a patient’s whole date or only his/her name, phone number, disease name, cabin number.
Related Articles
Inquiries
If you have any questions or suggestions about Simple Hospital Management System In C , please feel free to leave a comment below.
Does this project use linked list from data structure if yes can u specify