From d0dffee14d36f3aebbbdef42fa7fa9081b2b7e1d Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 22 Apr 2011 03:12:50 +0200 Subject: [PATCH] wip --- .gitignore | 1 + Makefile | 9 +++++---- brmbar.c | 41 +++++++++++++++++++++++++++++++++-------- defines.h | 1 + people.txt | 5 +++++ 5 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 people.txt diff --git a/.gitignore b/.gitignore index 0f6fb99..c351c70 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +brmbar brmbar.com diff --git a/Makefile b/Makefile index 340c194..c68511f 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,12 @@ CC=bcc CFLAGS=-Md -W -brmbar.com: brmbar.c defines.h - $(CC) $(CFLAGS) brmbar.c -o brmbar.com +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 -run: +dos: dosbox brmbar.com diff --git a/brmbar.c b/brmbar.c index 2f23434..daaa4d6 100644 --- a/brmbar.c +++ b/brmbar.c @@ -1,4 +1,5 @@ #include +#include #include "defines.h" struct item { @@ -7,7 +8,10 @@ struct item { int price; } items[ITEM_MAXNUM]; +char *people[PERSON_MAXLEN]; + int items_count; +int people_count; void fill_items() { @@ -15,7 +19,17 @@ void fill_items() FILE *f = fopen("items.txt", "r"); while (fgets(buf, 128, f)) { printf("%s\n", buf); - } + } + fclose(f); +} + +void fill_people() +{ + FILE *f = fopen("people.txt", "r"); + people_count = 0; + while (fgets(people[people_count], PERSON_MAXLEN , f)) { + ++people_count; + } fclose(f); } @@ -25,8 +39,8 @@ int read_item() { for (;;) { printf("i> "); if (fgets(buf, 128, stdin)) { - for (i = 0; ; ++i) { - if (!strncmp( buf, items[0].ean, strlen(items[0].ean) )) { + for (i = 0; i < items_count; ++i) { + if (!strncmp( buf, items[i].ean, strlen(items[i].ean) )) { return i; } } @@ -35,18 +49,29 @@ int read_item() { } } -int read_action() { - return 0; +int read_person() { + char buf[128]; + int i; + for (;;) { + printf("p> "); + if (fgets(buf, 128, stdin)) { + for (i = 0; i < people_count; ++i) { + if (!strncmp( buf, people[0], strlen(people[0]) )) { + return i; + } + } + printf("Unknown person %s\n", buf); + } + } } int main() { - int i, a; + int i, p; fill_items(); for (;;) { i = read_item(); - a = read_action(); + p = read_person(); } return 0; } - diff --git a/defines.h b/defines.h index 694f74c..76daf00 100644 --- a/defines.h +++ b/defines.h @@ -4,6 +4,7 @@ #define EAN_MAXLEN 32 #define NAME_MAXLEN 128 #define ITEM_MAXNUM 128 +#define PERSON_MAXLEN 16 #endif diff --git a/people.txt b/people.txt new file mode 100644 index 0000000..e893069 --- /dev/null +++ b/people.txt @@ -0,0 +1,5 @@ +biiter +czestmyr +niekt0 +stick +tomsuch