mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-08 05:14:00 +02:00
Added dataio.h/c
Signed-off-by: Cestmir Houska <czestmyr@gmail.com>
This commit is contained in:
parent
3d8cbd98b4
commit
948d2630a4
3 changed files with 48 additions and 2 deletions
4
Makefile
4
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
|
||||
|
|
39
dataio.c
Normal file
39
dataio.c
Normal 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
7
dataio.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef _BRMBAR_DATAIO_H_
|
||||
#define _BRMBAR_DATAIO_H_
|
||||
|
||||
extern int modify_credit(name, price);
|
||||
|
||||
#endif
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue