forked from brmlab/brmbar-github
code done
This commit is contained in:
parent
dd772c2ea3
commit
0ed434d9d2
4 changed files with 16 additions and 12 deletions
6
Makefile
6
Makefile
|
@ -1,9 +1,9 @@
|
||||||
CC=bcc
|
CC=bcc
|
||||||
CFLAGS=-Md -W
|
CFLAGS=-Md -W
|
||||||
|
|
||||||
all: brmbar.c defines.h
|
all: brmbar.c
|
||||||
gcc -Wall brmbar.c -o brmbar
|
# gcc brmbar.c dataio.c -o brmbar
|
||||||
bcc -Md -W brmbar.c -o brmbar.com
|
bcc -Md -W brmbar.c dataio.c -o brmbar.com
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f brmbar.com brmbar
|
rm -f brmbar.com brmbar
|
||||||
|
|
3
brmbar.c
3
brmbar.c
|
@ -1,5 +1,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "dataio.h"
|
||||||
|
|
||||||
#define EAN_MAXLEN 32
|
#define EAN_MAXLEN 32
|
||||||
#define NAME_MAXLEN 128
|
#define NAME_MAXLEN 128
|
||||||
|
@ -95,7 +96,7 @@ void read_input()
|
||||||
|
|
||||||
// scan items
|
// scan items
|
||||||
for (i = 0; i < items_count; ++i) {
|
for (i = 0; i < items_count; ++i) {
|
||||||
if (!strncmp(buf, items[i].ean, strlen(items[i].ean))) {
|
if (!strncmp(buf, items[i].ean, strlen(items[i].ean)) && strlen(items[i].ean)+1 == strlen(buf)) {
|
||||||
if (items[i].price) {
|
if (items[i].price) {
|
||||||
last_item = i;
|
last_item = i;
|
||||||
printf("\n%s %d Kc\n\n", items[i].name, items[i].price);
|
printf("\n%s %d Kc\n\n", items[i].name, items[i].price);
|
||||||
|
|
18
dataio.c
18
dataio.c
|
@ -6,19 +6,24 @@ int modify_credit(name, price)
|
||||||
const char* name;
|
const char* name;
|
||||||
int price;
|
int price;
|
||||||
{
|
{
|
||||||
char filename[13];
|
char filename[20];
|
||||||
int i;
|
int i;
|
||||||
int credit;
|
int credit;
|
||||||
FILE* person_data;
|
FILE* person_data;
|
||||||
|
|
||||||
strncpy(filename, name, 8);
|
strcpy(filename, "DATA\\");
|
||||||
i = strlen(name);
|
i = 5;
|
||||||
if (i > 8) i = 8;
|
strncpy(&filename[i], name, 8);
|
||||||
|
if (strlen(name) > 8) {
|
||||||
|
i += 8;
|
||||||
|
} else {
|
||||||
|
i += strlen(name);
|
||||||
|
}
|
||||||
strcpy(&filename[i], ".txt");
|
strcpy(&filename[i], ".txt");
|
||||||
person_data = fopen(filename, "r");
|
person_data = fopen(filename, "r");
|
||||||
|
|
||||||
if (person_data == NULL) {
|
if (person_data == NULL) {
|
||||||
printf("Warning: Filename %s does not exist!\n", filename);
|
// printf("Warning: Filename %s does not exist!\n", filename);
|
||||||
credit = 0;
|
credit = 0;
|
||||||
} else {
|
} else {
|
||||||
fscanf(person_data, "%i", &credit);
|
fscanf(person_data, "%i", &credit);
|
||||||
|
@ -30,7 +35,7 @@ int modify_credit(name, price)
|
||||||
credit += price;
|
credit += price;
|
||||||
person_data = fopen(filename, "w");
|
person_data = fopen(filename, "w");
|
||||||
if (person_data == NULL) {
|
if (person_data == NULL) {
|
||||||
printf("ERROR: Filename %s could not be created or overwritten!\nCheck system integrity!\n", filename);
|
// printf("ERROR: Filename %s could not be created or overwritten!\nCheck system integrity!\n", filename);
|
||||||
} else {
|
} else {
|
||||||
fprintf(person_data, "%i", credit);
|
fprintf(person_data, "%i", credit);
|
||||||
fclose(person_data);
|
fclose(person_data);
|
||||||
|
@ -39,4 +44,3 @@ int modify_credit(name, price)
|
||||||
|
|
||||||
return credit;
|
return credit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
dataio.h
1
dataio.h
|
@ -4,4 +4,3 @@
|
||||||
extern int modify_credit(name, price);
|
extern int modify_credit(name, price);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue