mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-07 21:04:00 +02:00
dataio.c: Modification by zero only reads the current credit
Signed-off-by: Cestmir Houska <czestmyr@gmail.com>
This commit is contained in:
parent
948d2630a4
commit
d8f8458dee
1 changed files with 11 additions and 8 deletions
5
dataio.c
5
dataio.c
|
@ -18,13 +18,15 @@ int modify_credit(name, price)
|
|||
person_data = fopen(filename, "r");
|
||||
|
||||
if (person_data == NULL) {
|
||||
printf("Warning: Filename %s does not exist! Creating...\n", filename);
|
||||
printf("Warning: Filename %s does not exist!\n", filename);
|
||||
credit = 0;
|
||||
} else {
|
||||
fscanf(person_data, "%i", &credit);
|
||||
fclose(person_data);
|
||||
}
|
||||
|
||||
// Write only if the price would change credit
|
||||
if (price != 0) {
|
||||
credit += price;
|
||||
person_data = fopen(filename, "w");
|
||||
if (person_data == NULL) {
|
||||
|
@ -33,6 +35,7 @@ int modify_credit(name, price)
|
|||
fprintf(person_data, "%i", credit);
|
||||
fclose(person_data);
|
||||
}
|
||||
}
|
||||
|
||||
return credit;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue