mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-08 21:33:59 +02:00
Merge branch 'master' of github.com:brmlab/brmbar
This commit is contained in:
commit
ead328225d
3 changed files with 47 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
||||||
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
|
||||||
|
|
||||||
|
|
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