What is DBMS
A DBMS (Database Management System) is a software application that interacts with end users, other applications, and the database itself to capture and analyze the data. A general-purpose DBMS allows the definition, creation, querying, update, and administration of databases. Examples of DBMS include MySQL, Oracle, and Microsoft SQL Server.
DBMS in C
This is a project written in C language. Which is divided into 21 function Whose source code is given in the next page with the file name, all these function have been exaplained in the source code itself in the comments.
This file links all header files and logo functions.
file name - "maha.h"
copy
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include "lable.c"
#include "data.c"
#include "pass_g.c"
#include "edit_delete.c"
#include "find.c"
void logo()
{
HANDLE hc = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hc, 12); // this function working on changing of color
puts("Creat DBMS in C By SA Coder, Website = https://www.sacoder.com/");
SetConsoleTextAttribute(hc, 7);
}
/* black 0, blue 1, green 2, aqua 3, red 4, purple 5, yellow 6, white 7, gray 8, light blue 9,light green 10, light aqua 11, light red 12, light purple 13, light yellow 14, white bright 15
*/
This file contain main function
dbms.c
copy
#include "maha.h"
int main()
{
FILE *fa;
long long pass;
int size = 11;
char *protect = (char *)malloc(sizeof(char) * 51);
char *file_name = (char *)malloc(sizeof(char) * 260);
logo();
printf("********************* Welcome TO Our Database Management System *********************\n\n");
while (1)
{
printf(" 1. Creat new database\n 2. Open exist database\n");
gets(protect);
if (strcmp("exit", protect) == 0 || strcmp("back", protect) == 0)
{
exit(0);
}
if (strcmp(protect, "1") == 0)
{
puts(" *** Important instruction -> use the separate folder ***\n\n Enter name of database");
while (1)
{
gets(file_name);
if (strcmp("exit", file_name) == 0)
{
exit(0);
}
if (strcmp("back", file_name) == 0)
{
break;
}
puts(" ---> Set your password <--- ");
gets(protect);
if (strcmp("exit", protect) == 0)
{
exit(0);
}
if (strcmp("back", protect) == 0)
{
break;
}
if ((fa = fopen(file_name, "wb+")) == 0)
{
puts("Error Please use the deferent name");
continue;
}
break;
}
if (fa == 0)
{
continue;
}
pass = password(protect, fa, 'a');
fwrite(&size, sizeof(size), 1, fa);
printf(" ---> your password is successfully added <--- \n");
break;
}
else if (strcmp(protect, "2") == 0)
{
while (1)
{
puts(" Enter name of database");
gets(file_name);
if (strcmp("exit", file_name) == 0)
{
exit(0);
}
printf(" ---> Enter Password <--- \n");
gets(protect);
if (strcmp("exit", protect) == 0)
{
exit(0);
}
if ((fa = fopen(file_name, "rb+")) != 0)
{
if (pass = password(protect, fa, 'c') != 0)
{
fread(&size, sizeof(size), 1, fa);
break;
}
else
{
printf(" ---> Wrong Password <--- \n");
fclose(fa);
continue;
}
}
else
{
puts(" Your database is not exist\n");
break;
}
}
if (fa == 0)
{
continue;
}
break;
}
else
{
puts("Enter wrong command");
}
}
char *lname = (char *)malloc(sizeof(char) * size);
while (1)
{
printf("\n\nEnter any Command \n 1. add_lable\n 2. add_data\n 3. find\n 4. show_all\n 5. delete_lable\n");
char command[15];
lname = (char *)realloc(lname, sizeof(char) * size);
fflush(stdin);
scanf("%s", command);
int temp;
if (strcmp("1", command) == 0 || strcmp("add_lable", command) == 0)
{
printf("your old size %d give me a new size and lable name\n", size - 1);
scanf("%d", &size);
fseek(fa, sizeof(pass), SEEK_SET);
size++;
fwrite(&size, sizeof(size), 1, fa);
scanf("%s", lname);
fflush(stdin);
temp = lable(lname, fa, &pass, size);
if (temp == 0)
{
printf(" ---> Successfully addad lable %s <--- \n", lname);
}
if (temp == -1)
{
printf(" ---> lable %s is already exists use the diffrent name <--- \n", lname);
}
if (temp == -2)
{
printf(" ---> lable %s not added use the diffrent name <--- \n", lname);
}
if (temp == -3)
{
printf(" ---> Some Error Occurred <--- \n");
}
fflush(stdin);
continue;
}
else if (strcmp("2", command) == 0 || strcmp("add_data", command) == 0)
{
fflush(stdin);
data(fa, pass);
fflush(stdin);
continue;
}
else if (strcmp("3", command) == 0 || strcmp("find", command) == 0)
{
find(fa);
continue;
}
else if (strcmp("4", command) == 0 || strcmp("show_all", command) == 0)
{
show_all(fa);
continue;
}
else if (strcmp("5", command) == 0 || strcmp("delete_lable", command) == 0)
{
scanf("%s", lname);
printf("If you want to remove lable %s\n Enter any key for cancel(Enter y for continue)", lname);
fflush(stdin);
if (getchar() == 'y')
{
fclose(fa);
delete2(file_name, lname);
fa = fopen(file_name, "rb+");
}
}
else if (strcmp("exit", command) == 0)
{
fclose(fa);
exit(0);
}
else if (strcmp("cls", command) == 0)
{
system("cls");
continue;
}
else if (strcmp("passw", command) == 0)
{
printf(" ---> Enter New Password <---\n");
fflush(stdin);
gets(protect);
if (strcmp("exit", protect) == 0)
{
exit(0);
}
pass = password(protect, fa, 'a');
printf(" ---> your password is successfully added <--- \n");
continue;
}
else
{
printf("\n Error your command not valid\n");
}
}
fclose(fa);
return 0;
}
Explain
An implementation of a database management system (DBMS) written in the C programming language. It allows the user to create a new database or open an existing one, add labels and data, find data, show all data, and delete labels.
The program first prompts the user to either create a new database or open an existing one. If the user chooses to create a new database, they are prompted to enter a name for the database and a password to protect it. If the user chooses to open an existing database, they are prompted to enter the database name and the password they previously set.
Once the database is opened or created, the user is prompted to enter a command. The available commands are: 1. add_lable: This command allows the user to add a new label to the database. 2. add_data: This command allows the user to add data to the database. 3. find: This command allows the user to search for data in the database. 4. show_all: This command displays all the data in the database. 5. delete_lable: This command allows the user to delete a label from the database. Each command is implemented in a separate function, with the function code given in the source code file "maha.h". The functions are called from the main function in the source code you provided, based on the user's command input. It is worth noting that the source code you provided is incomplete and does not include the implementation of all the necessary functions to fully run the DBMS.
Click on the next button for source code of next file