From: Maik Fischer Date: Thu, 26 Oct 2017 11:38:16 +0000 (+0200) Subject: kasse: use cgetn_input() to simplify logic X-Git-Tag: rgb2rv17~9^2~13 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b5072525db877edaf2194fa5decbd19f6fc51600;p=c128-kasse kasse: use cgetn_input() to simplify logic --- diff --git a/include/general.h b/include/general.h index 82a0db9..e07176e 100644 --- a/include/general.h +++ b/include/general.h @@ -12,6 +12,7 @@ typedef input_terminator_t input_terminator_mask_t; input_terminator_t get_input_terminated_by(input_terminator_mask_t terminators, char *out, BYTE outlen); char *get_input(void); +BYTE cgetn_input(char *s, BYTE len); void cget_return(void); char retry_or_quit(void); char *format_euro(char *s, int maxlen, int cent); diff --git a/src/general.c b/src/general.c index 87cdd07..91318aa 100644 --- a/src/general.c +++ b/src/general.c @@ -66,7 +66,12 @@ char *get_input(void) { return output; } -/* wait until user pressed RETURN, ignore all other input */ +BYTE cgetn_input(char *s, BYTE len) { + memset(s, '\0', len); + get_input_terminated_by(INPUT_TERMINATOR_RETURN, s, len); + return strlen(s); +} + void cget_return() { BYTE c; while (1) { diff --git a/src/kasse.c b/src/kasse.c index aa112f3..b59d44d 100644 --- a/src/kasse.c +++ b/src/kasse.c @@ -348,15 +348,12 @@ void buy_custom(void) { BYTE c = 0, i = 0; int negative = 1; char entered[5] = {'1', 0, 0, 0, 0}; - char *input, name[20]; + char name[MAX_ITEM_NAME_LENGTH + 1]; int price; clrscr(); - memset(name, '\0', sizeof(name)); cprintf("\r\nWas soll gekauft werden?\r\n"); - input = get_input(); - strncpy(name, input, sizeof(name)); - if (*name == '\0') + if (cgetn_input(name, sizeof(name)) == 0) return; cprintf("\r\nWie teuer ist \"%s\" (in cents)?\r\n", name);