diff --git a/src/CustomerData.txt b/src/CustomerData.txt index 3ac070f..782579a 100644 --- a/src/CustomerData.txt +++ b/src/CustomerData.txt @@ -1,6 +1 @@ -1234=example -ID=1234 -forename=Max -Surname=Mustermann -password=example -balance=0 +balance=500 \ No newline at end of file diff --git a/src/TempData.txt b/src/TempData.txt new file mode 100644 index 0000000..f81d5a8 --- /dev/null +++ b/src/TempData.txt @@ -0,0 +1,5 @@ +1234=example +ID=1234 +forename=Max +Surname=Mustermann +balance=0 diff --git a/src/a.exe b/src/a.exe new file mode 100644 index 0000000..25d0c58 Binary files /dev/null and b/src/a.exe differ diff --git a/src/updateCustomerAccountBalance.c b/src/updateCustomerAccountBalance.c new file mode 100644 index 0000000..48ad5e8 --- /dev/null +++ b/src/updateCustomerAccountBalance.c @@ -0,0 +1,95 @@ +#include "updateCustomerAccountBalance.h" +#include "currentCustomerAccountBalance.c" + +void deleteLineFromFile(int line){ + FILE *fptr1, *fptr2; + char file1[] ="CustomerData.txt"; + char file2[] ="TempData.txt"; + char curr; + int del=line, line_number = 0; + fptr1 = fopen(file1,"r"); + fptr2 = fopen(file2, "w"); + curr = getc(fptr1); + if(curr!=EOF) {line_number =1;} + while(1){ + if(del != line_number){ + putc(curr, fptr2); + curr = getc(fptr1); + if(curr =='\n') line_number++; + if(curr == EOF) break; + }else{ + + } + + } + fclose(fptr1); + remove(file1); + fclose(fptr2); + rename(file2,"CustomerData.txt"); + +} + +void replaceBalanceInString(float replacementBalance, int currentLine) { + deleteLineFromFile(currentLine-1); + printf("deleting from line %i. balance will be replaced with %f", currentLine, replacementBalance); + char newBalanceLine[MAX_LENGTH] = "balance="; + char balance_as_string[MAX_LENGTH]; + sprintf(balance_as_string, "%g", replacementBalance); //converts replacement balance to string + strcat(newBalanceLine, balance_as_string); + printf(newBalanceLine); + + char buffer[MAX_LENGTH]; + FILE *file = fopen("CustomerData.txt", "w"); + + for(int i=0;i +#include +#include +#include + +#define MAX_LENGTH 100 +bool updateAvailableAccountBalance(int user_id, float changeInBalance); +void deleteLineFromFile(int lineNumber); +void replaceBalanceInString(float replacementBalance, int currentLine); \ No newline at end of file