46void displayWelcomeMessage(
void) {
47 FILE* file = fopen(
"resources/assets/misc/cc.txt",
"r");
52 while (fgets(buffer,
sizeof(buffer), file) != NULL) {
65void displayUserMenu(
void) {
66 printf(
"\n--- CrimsonCare Blood Bank Management System (User) ---\n");
67 printf(
"1. Buy Blood\n");
68 printf(
"2. Sell Blood\n");
69 printf(
"3. Display Blood Stocks\n");
70 printf(
"4. Admin Panel\n");
72 printf(
"Select an option: ");
82void displayAdminMenu(
void) {
83 printf(
"\n--- CrimsonCare Blood Bank Management System (Admin) ---\n");
84 printf(
"1. Add Hospital\n");
85 printf(
"2. Update Blood Quantity\n");
86 printf(
"3. Update Blood Price\n");
87 printf(
"4. Change Admin Password\n");
88 printf(
"5. Add Admin\n");
89 printf(
"6. Delete Admin\n");
90 printf(
"7. Delete Hospital\n");
91 printf(
"8. Display Admins\n");
92 printf(
"9. Display Hospitals\n");
93 printf(
"10. Display Blood Stocks\n");
94 printf(
"11. Display Transactions\n");
96 printf(
"Select an option: ");
107void clearInputBuffer(
void) {
109 while ((c = getchar()) !=
'\n' && c != EOF);
127bool checkUsername(
const char* str) {
129 if (!(*str >=
'a' && *str <=
'z') && !(*str >=
'0' && *str <=
'9')) {
150bool containsPipe(
const char* str) {
172void getPassword(
char* password,
size_t size) {
176 while (i < size - 1) {
183 }
else if (ch ==
'\b') {
201 struct termios oldt, newt;
202 tcgetattr(STDIN_FILENO, &oldt);
206 newt.c_lflag &= ~(ECHO);
208 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
210 fgets(password, size);
211 password[strcspn(password,
"\n")] = 0;
213 tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
228bool isLeapYear(
int year) {
229 return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
248bool isValidDate(
const char* date) {
249 if (strcmp(date,
"") == 0) {
250 printf(
"Error: Date cannot be empty.\n");
254 int year, month, day;
256 if (strlen(date) < 8 || strlen(date) > 10) {
257 printf(
"Error: Invalid date format.\n");
261 if (sscanf(date,
"%d-%d-%d", &year, &month, &day) != 3) {
262 printf(
"Error: Invalid date format.\n");
266 if (month < 1 || month > 12) {
267 printf(
"Error: Invalid month.\n");
271 int daysInMonth[] = { 31, 28 + (int)isLeapYear(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
273 if (day < 1 || day > daysInMonth[month - 1]) {
274 printf(
"Error: Invalid day.\n");
294void formatDate(
char* date) {
295 if (strcmp(date,
"") == 0) {
296 printf(
"Error: Date cannot be empty.\n");
300 if (!isValidDate(date)) {
301 printf(
"Error: Invalid date format.\n");
305 int year, month, day;
306 sscanf(date,
"%d-%d-%d", &year, &month, &day);
307 sprintf(date,
"%04d-%02d-%02d", year, month, day);