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