From e9e2ea78fa012e909aff1b0f0838c321e496fb67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Sat, 17 Jul 2021 22:42:03 +0800 Subject: nitems include item quantities that are more than 1 --- anteraja.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/anteraja.c b/anteraja.c index 0e5f2e7..a3bc1c3 100644 --- a/anteraja.c +++ b/anteraja.c @@ -112,15 +112,15 @@ void anteraja_order(const char *order_number, const char *service, const char *s + ORDER_ITEM_PRICE + ORDER_ITEM_WEIGHT - strlen("%s") - 3 * strlen("%d") + strlen(","); char item[length + 1]; - double weight = atof(items[i][WEIGHT]) * 1000.0; - if (weight < 100.0) - weight = 100.0; + int quantity = atoi(items[i][QUANTITY]); double price = atof(items[i][PRICE]); if (price < 1000.0) price = 1000.0; - sprintf(item, ORDER_ITEM, items[i][DESCRIPTION], atoi(items[i][QUANTITY]), (int)price, - (int)weight); + double weight = atof(items[i][WEIGHT]) * 1000.0; + if (weight < 100.0) + weight = 100.0; total_weight += weight; + sprintf(item, ORDER_ITEM, items[i][DESCRIPTION], quantity, (int)price, (int)weight); if (json) json = realloc(json, strlen(json) + length + 1); else { @@ -132,6 +132,7 @@ void anteraja_order(const char *order_number, const char *service, const char *s strcat(json, ","); else json[strlen(json)] = '\0'; + i += quantity - 1; } *post = malloc(strlen(ORDER_POST) + strlen(prefix) + strlen(order_number) + strlen(service) + ORDER_WEIGHT + strlen(sender_name) + strlen(sender_phone) + strlen(origin) -- cgit v1.2.3