|
|
@ -17,6 +17,9 @@ void troubleShoot(int errorCode){ |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
printf("Renaming of a file failed. Are you sure the bank management system has the required authorization to rename files?"); |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
printf("Could not find the customer. Please contact customer support."); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -61,12 +64,13 @@ void replaceBalanceInString(float replacementBalance, int currentLine) { |
|
|
|
char balance_as_string[MAX_LENGTH]; |
|
|
|
sprintf(balance_as_string, "%f", replacementBalance); //converts replacement balance to string |
|
|
|
strcat(newBalanceLine, balance_as_string); |
|
|
|
replaceLineInFile("CustomerData.txt",currentLine,newBalanceLine); |
|
|
|
replaceLineInFile(CUSTOMER_DATA_FILE,currentLine,newBalanceLine); |
|
|
|
} |
|
|
|
|
|
|
|
bool updateAvailableAccountBalance(int user_id, float newBalance){ |
|
|
|
|
|
|
|
bool keep_reading = true; |
|
|
|
bool foundCustomer = false; |
|
|
|
|
|
|
|
char *buffer = malloc(MAX_LENGTH * sizeof(char)); |
|
|
|
char *stringID = malloc(MAX_LENGTH * sizeof(char)); |
|
|
@ -78,7 +82,7 @@ bool updateAvailableAccountBalance(int user_id, float newBalance){ |
|
|
|
sprintf(user_id_as_string, "%d", user_id); // converts user_id to string |
|
|
|
strcat(stringID, user_id_as_string); |
|
|
|
|
|
|
|
FILE *file = fopen("CustomerData.txt", "r"); |
|
|
|
FILE *file = fopen(CUSTOMER_DATA_FILE, "r"); |
|
|
|
//printf(stringID); |
|
|
|
while(keep_reading) { |
|
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
@ -93,10 +97,17 @@ bool updateAvailableAccountBalance(int user_id, float newBalance){ |
|
|
|
} |
|
|
|
strcpy(balance_String, buffer); |
|
|
|
keep_reading = false; |
|
|
|
foundCustomer=true; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
fclose(file);; |
|
|
|
replaceBalanceInString(newBalance,currentLine); |
|
|
|
fclose(file); |
|
|
|
|
|
|
|
if(foundCustomer){ |
|
|
|
replaceBalanceInString(newBalance,currentLine); |
|
|
|
}else{ |
|
|
|
troubleShoot(4); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |