diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/save.c | 1 | ||||
| -rw-r--r-- | src/sell.c | 4 | ||||
| -rw-r--r-- | src/util.c | 12 |
3 files changed, 7 insertions, 10 deletions
@@ -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); @@ -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); @@ -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) |