59bool isValidBloodGroup(uint32_t
id) {
83bool addBloodGroup(uint32_t
id,
const char* bloodGroup,
float price, uint32_t quantity) {
84 if (strcmp(bloodGroup,
"") == 0) {
85 printf(
"Error: Invalid blood group data.\n");
89 if (!isValidBloodGroup(
id)) {
90 printf(
"Error: Invalid blood group id.\n");
96 printf(
"Error allocating memory for blood group: %s\n", strerror(errno));
101 newGroup->
price = price;
104 newGroup->
next = NULL;
110 while (temp->
next != NULL) {
113 temp->
next = newGroup;
128void initializeBloodGroups(
void) {
149void saveBloodGroups(
void) {
151 FILE* file = fopen(
"resources/db/blood_data.txt",
"w");
153 if (errno != ENOENT) {
154 printf(
"Error opening blood data file: %s\n", strerror(errno));
160 while (temp != NULL) {
183bool updateBloodQuantity(uint32_t
id, uint32_t newQuantity) {
184 if (!isValidBloodGroup(
id)) {
185 printf(
"Error: Invalid blood group id.\n");
190 while (temp != NULL) {
191 if (temp->
id ==
id) {
217bool updateBloodPrice(uint32_t
id,
float newPrice) {
218 if (!isValidBloodGroup(
id)) {
219 printf(
"Error: Invalid blood group id.\n");
224 while (temp != NULL) {
225 if (temp->
id ==
id) {
226 temp->
price = newPrice;
249void loadBloodGroups(
void) {
251 FILE* file = fopen(
"resources/db/blood_data.txt",
"r");
253 if (errno == ENOENT) {
254 initializeBloodGroups();
257 printf(
"Error opening blood data file: %s\n", strerror(errno));
266 printf(
"Error allocating memory for blood group: %s\n", strerror(errno));
278 newBlood->
next = NULL;
284 while (temp->
next != NULL) {
287 temp->
next = newBlood;
314 if (type !=
BUY && type !=
SELL) {
315 printf(
"Error: Invalid transaction type.\n");
319 if (
id != NULL && !isValidBloodGroup(*
id)) {
320 printf(
"Error: Invalid blood group id.\n");
325 while (temp != NULL) {
338 if (temp->
price > 0) {
342 if (temp->
id == *
id && temp->
price > 0) {
359void displayBloodGroups(
void) {
374void displayBloodStocks(
void) {
377 printf(
"No blood available.\n");
380 printf(
"\nAvailable Blood:\n");
381 while (temp != NULL) {
382 if (temp->
price > 0.0) {
385 printf(
"%u. %s, Price: N/A, Quantity: N/A\n", temp->
id, temp->
bloodGroup);
404char* getBloodGroupById(uint32_t
id) {
405 if (!isValidBloodGroup(
id)) {
406 printf(
"Error: Invalid blood group id.\n");
420void freeBloodList(
void) {
422 while (current != NULL) {
424 current = current->
next;
char * availableBloodGroups[8]
Blood groups.
Blood manager header file.
#define BLOOD_GROUP_NAME_LENGTH
Blood group name length.
BloodStock * bloodHead
Globally exposed blood stock head pointer.
char bloodGroup[BLOOD_GROUP_NAME_LENGTH]
Transaction manager header file.
TransactionType
Transaction type enum.