mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-08 05:14:00 +02:00
Merge branch 'master' of github.com:brmlab/brmbar
This commit is contained in:
commit
dd772c2ea3
1 changed files with 11 additions and 8 deletions
19
dataio.c
19
dataio.c
|
@ -18,20 +18,23 @@ int modify_credit(name, price)
|
||||||
person_data = fopen(filename, "r");
|
person_data = fopen(filename, "r");
|
||||||
|
|
||||||
if (person_data == NULL) {
|
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;
|
credit = 0;
|
||||||
} else {
|
} else {
|
||||||
fscanf(person_data, "%i", &credit);
|
fscanf(person_data, "%i", &credit);
|
||||||
fclose(person_data);
|
fclose(person_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
credit += price;
|
// Write only if the price would change credit
|
||||||
person_data = fopen(filename, "w");
|
if (price != 0) {
|
||||||
if (person_data == NULL) {
|
credit += price;
|
||||||
printf("ERROR: Filename %s could not be created or overwritten!\nCheck system integrity!\n", filename);
|
person_data = fopen(filename, "w");
|
||||||
} else {
|
if (person_data == NULL) {
|
||||||
fprintf(person_data, "%i", credit);
|
printf("ERROR: Filename %s could not be created or overwritten!\nCheck system integrity!\n", filename);
|
||||||
fclose(person_data);
|
} else {
|
||||||
|
fprintf(person_data, "%i", credit);
|
||||||
|
fclose(person_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return credit;
|
return credit;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue