|
@ -2,10 +2,29 @@ |
|
|
#include "currentCustomerAccountBalance.c" |
|
|
#include "currentCustomerAccountBalance.c" |
|
|
#include "lineReplacer.h" |
|
|
#include "lineReplacer.h" |
|
|
|
|
|
|
|
|
|
|
|
void troubleShoot(int errorCode){ |
|
|
|
|
|
printf("Error! The requested operation was terminated because of an issue. Here are some details about the error:\n---------------\n"); |
|
|
|
|
|
|
|
|
|
|
|
switch(errorCode){ |
|
|
|
|
|
case 0: |
|
|
|
|
|
printf("Requested file could not be opened. Are you sure it exists?"); |
|
|
|
|
|
break; |
|
|
|
|
|
case 1: |
|
|
|
|
|
printf("A temporary file could not be generated. Are you sure the bank management system has the required authorization to create new files?"); |
|
|
|
|
|
break; |
|
|
|
|
|
case 2: |
|
|
|
|
|
printf("Replacement of the old file failed. Are you sure the bank management system has the required authorization to delete files?"); |
|
|
|
|
|
break; |
|
|
|
|
|
case 3: |
|
|
|
|
|
printf("Renaming of a file failed. Are you sure the bank management system has the required authorization to rename files?"); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void replaceLineInFile(const char* file_name, int line, const char* new_line){ |
|
|
void replaceLineInFile(const char* file_name, int line, const char* new_line){ |
|
|
FILE* file = fopen(file_name, "r"); |
|
|
FILE* file = fopen(file_name, "r"); |
|
|
if (file == NULL) { |
|
|
if (file == NULL) { |
|
|
printf("Error opening file!\n"); |
|
|
|
|
|
|
|
|
troubleShoot(0); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
char current_string[100]; |
|
|
char current_string[100]; |
|
@ -14,7 +33,7 @@ void replaceLineInFile(const char* file_name, int line, const char* new_line){ |
|
|
temp_file_name = "temp.txt"; |
|
|
temp_file_name = "temp.txt"; |
|
|
FILE* temp_file = fopen(temp_file_name, "w"); |
|
|
FILE* temp_file = fopen(temp_file_name, "w"); |
|
|
if (temp_file == NULL) { |
|
|
if (temp_file == NULL) { |
|
|
printf("Error creating temp file!\n"); |
|
|
|
|
|
|
|
|
troubleShoot(1); |
|
|
fclose(file); |
|
|
fclose(file); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -30,10 +49,10 @@ void replaceLineInFile(const char* file_name, int line, const char* new_line){ |
|
|
fclose(file); |
|
|
fclose(file); |
|
|
fclose(temp_file); |
|
|
fclose(temp_file); |
|
|
if(remove(file_name)!=0){ |
|
|
if(remove(file_name)!=0){ |
|
|
printf("could not remove the original file!"); |
|
|
|
|
|
|
|
|
troubleShoot(2); |
|
|
} // Remove the original file |
|
|
} // Remove the original file |
|
|
if(rename(temp_file_name, file_name)!=0){ |
|
|
if(rename(temp_file_name, file_name)!=0){ |
|
|
printf("could not rename!"); |
|
|
|
|
|
|
|
|
troubleShoot(3); |
|
|
} // Rename the temp file to the original file |
|
|
} // Rename the temp file to the original file |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -68,12 +87,11 @@ bool updateAvailableAccountBalance(int user_id, float newBalance){ |
|
|
keep_reading = false; |
|
|
keep_reading = false; |
|
|
} |
|
|
} |
|
|
else if(strstr(buffer, stringID)) { //found the customer |
|
|
else if(strstr(buffer, stringID)) { //found the customer |
|
|
|
|
|
for (int i = 0; i < 4; i++) { |
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
|
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
|
|
|
fgets(buffer, MAX_LENGTH, file); |
|
|
|
|
|
|
|
|
currentLine++; |
|
|
|
|
|
} |
|
|
strcpy(balance_String, buffer); |
|
|
strcpy(balance_String, buffer); |
|
|
currentLine+=4; |
|
|
|
|
|
keep_reading = false; |
|
|
keep_reading = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|