forked from brmlab/brmbar-github
reorganization
This commit is contained in:
parent
bdd9f6ac92
commit
fd6e33a390
11 changed files with 19 additions and 11 deletions
46
dataio.c
46
dataio.c
|
@ -1,46 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "dataio.h"
|
||||
|
||||
int modify_credit(name, price)
|
||||
const char* name;
|
||||
int price;
|
||||
{
|
||||
char filename[20];
|
||||
int i;
|
||||
int credit;
|
||||
FILE* person_data;
|
||||
|
||||
strcpy(filename, "DATA\\");
|
||||
i = 5;
|
||||
strncpy(&filename[i], name, 8);
|
||||
if (strlen(name) > 8) {
|
||||
i += 8;
|
||||
} else {
|
||||
i += strlen(name);
|
||||
}
|
||||
strcpy(&filename[i], ".txt");
|
||||
person_data = fopen(filename, "r");
|
||||
|
||||
if (person_data == NULL) {
|
||||
// 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) {
|
||||
// printf("ERROR: Filename %s could not be created or overwritten!\nCheck system integrity!\n", filename);
|
||||
} else {
|
||||
fprintf(person_data, "%i", credit);
|
||||
fclose(person_data);
|
||||
}
|
||||
}
|
||||
|
||||
return credit;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue