Added dataio.h/c

Signed-off-by: Cestmir Houska <czestmyr@gmail.com>
This commit is contained in:
Cestmir Houska 2011-04-22 04:25:15 +02:00
parent 3d8cbd98b4
commit 948d2630a4
3 changed files with 48 additions and 2 deletions

View file

@ -1,12 +1,12 @@
CC=bcc CC=bcc
CFLAGS=-Md -W CFLAGS=-Md -W
all: brmbar.c all: brmbar.c defines.h
gcc -Wall brmbar.c -o brmbar gcc -Wall brmbar.c -o brmbar
bcc -Md -W brmbar.c -o brmbar.com bcc -Md -W brmbar.c -o brmbar.com
clean: clean:
rm -f brmbar.com rm -f brmbar.com brmbar
dos: dos:
dosbox brmbar.com dosbox brmbar.com

39
dataio.c Normal file
View file

@ -0,0 +1,39 @@
#include <stdio.h>
#include <string.h>
#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;
}

7
dataio.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef _BRMBAR_DATAIO_H_
#define _BRMBAR_DATAIO_H_
extern int modify_credit(name, price);
#endif