From 2ffadc256f7d7e5f0c3fc5f58aef4191eaa2607b Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Fri, 15 May 2015 19:14:24 -0400 Subject: stuff --- src/save.c | 1 - src/sell.c | 4 +++- src/util.c | 12 ++++-------- 3 files changed, 7 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/save.c b/src/save.c index 9028bb4..6cd2af2 100644 --- a/src/save.c +++ b/src/save.c @@ -64,7 +64,6 @@ void save_handler(struct player_t *player) struct history_item *hist = stock->history; while(hist) { - printf("WRITING HISTORY ITEM %d\n", hist->action); write_be32(f, hist->action); write_be64(f, hist->count); write_be64(f, hist->price.cents); diff --git a/src/sell.c b/src/sell.c index e490711..af4a9aa 100644 --- a/src/sell.c +++ b/src/sell.c @@ -19,7 +19,9 @@ void sell_handler(struct player_t *player) return; } - update_handler(player); + printf("Updating prices...\n"); + + get_stock_info(stock->symbol, &stock->current_price, &stock->fullname); printf("You currently own %llu shares of '%s' (%s) valued at $%llu.%02llu each.\n", stock->count, stock->fullname, stock->symbol, stock->current_price.cents / 100, stock->current_price.cents % 100); diff --git a/src/util.c b/src/util.c index eb50566..11da5c7 100644 --- a/src/util.c +++ b/src/util.c @@ -109,15 +109,12 @@ bool get_stock_info(char *symbol, struct money_t *price, char **name_ret) free(buf.data); - /* remove the decimal point */ + ullong dollars, cents; - for(int i = 0; i < price_len; ++i) - { - if(pricebuf[i] == '.') - memmove(pricebuf + i, pricebuf + i + 1, price_len - i); - } + /* dirty hack! */ + sscanf(pricebuf, "%llu.%2llu", &dollars, ¢s); - price->cents = strtoull(pricebuf, NULL, 10); + price->cents = dollars * 100 + cents; free(pricebuf); @@ -199,7 +196,6 @@ uint16_t to_sys16(uint16_t n) struct stock_t *find_stock(struct player_t *player, char *sym) { - printf("find stock %s\n", sym); for(int i = 0; i < player->portfolio_len; ++i) { if(strcmp(player->portfolio[i].symbol, sym) == 0) -- cgit v1.1