|
|
@ -0,0 +1,45 @@ |
|
|
|
#include "currentCustomerAccountBalance.h" |
|
|
|
|
|
|
|
float getAvailableAccountBalance(int user_id) { |
|
|
|
bool keep_reading = true; |
|
|
|
float balance = 0; |
|
|
|
|
|
|
|
char buffer[MAX_LENGTH]; |
|
|
|
char stringID[MAX_LENGTH] = "ID="; |
|
|
|
char user_id_as_string[MAX_LENGTH]; |
|
|
|
char balance_String[MAX_LENGTH]; |
|
|
|
|
|
|
|
sprintf(user_id_as_string, "%d", user_id); |
|
|
|
strcat(stringID, user_id_as_string); |
|
|
|
|
|
|
|
FILE *file = fopen("CustomerData.txt", "r"); |
|
|
|
|
|
|
|
while(keep_reading) { |
|
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
|
if (feof(file)) { |
|
|
|
keep_reading = false; |
|
|
|
} |
|
|
|
else if(strstr(buffer, stringID)) { |
|
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
|
strcpy(balance_String, buffer); |
|
|
|
|
|
|
|
char *token = strtok(balance_String, "="); |
|
|
|
while (token != NULL) { |
|
|
|
if (atoi(token) != 0) { |
|
|
|
balance = atof(token); |
|
|
|
break; |
|
|
|
} |
|
|
|
token = strtok(NULL, "="); |
|
|
|
} |
|
|
|
keep_reading = false; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
fclose(file); |
|
|
|
|
|
|
|
return balance; |
|
|
|
|
|
|
|
} |