diff --git a/Makefile b/Makefile index e30beb3..c68511f 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ CC=bcc CFLAGS=-Md -W -all: brmbar.c +all: brmbar.c defines.h gcc -Wall brmbar.c -o brmbar bcc -Md -W brmbar.c -o brmbar.com clean: - rm -f brmbar.com + rm -f brmbar.com brmbar dos: dosbox brmbar.com diff --git a/dataio.c b/dataio.c new file mode 100644 index 0000000..4dd42f8 --- /dev/null +++ b/dataio.c @@ -0,0 +1,39 @@ +#include +#include +#include "dataio.h" + +int modify_credit(name, price) + const char* name; + int price; +{ + char filename[13]; + int i; + int credit; + FILE* person_data; + + strncpy(filename, name, 8); + i = strlen(name); + if (i > 8) i = 8; + strcpy(&filename[i], ".txt"); + person_data = fopen(filename, "r"); + + if (person_data == NULL) { + printf("Warning: Filename %s does not exist! Creating...\n", filename); + credit = 0; + } else { + fscanf(person_data, "%i", &credit); + fclose(person_data); + } + + 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; +} + diff --git a/dataio.h b/dataio.h new file mode 100644 index 0000000..3e7d340 --- /dev/null +++ b/dataio.h @@ -0,0 +1,7 @@ +#ifndef _BRMBAR_DATAIO_H_ +#define _BRMBAR_DATAIO_H_ + +extern int modify_credit(name, price); + +#endif +