From 59b23fd18c63022b063ed2a65769ee2642e651e9 Mon Sep 17 00:00:00 2001 From: Paul Dino Jones Date: Sun, 29 Jan 2023 22:41:25 +0000 Subject: [PATCH] Fixed string format and spacing issue with car and driver strings. Insure number of cars displayed does not exceed number of cars in memory. --- src/gilles/gameloop/gameloop.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/gilles/gameloop/gameloop.c b/src/gilles/gameloop/gameloop.c index 4b71e57..759ff89 100644 --- a/src/gilles/gameloop/gameloop.c +++ b/src/gilles/gameloop/gameloop.c @@ -466,9 +466,13 @@ int looper(Simulator simulator, Parameters* p) // this will take some work and testing int thisx, thisy; getmaxyx(win4, thisx, thisy); - int maxcars = thisy/5; - int displaycars = maxcars; - if (simdata->numcars < maxcars) + int maxdispcars = thisy/5; + int displaycars = maxdispcars; + if (displaycars > MAXCARS) + { + displaycars = MAXCARS; + } + if (simdata->numcars < displaycars) { displaycars = simdata->numcars; } @@ -482,9 +486,10 @@ int looper(Simulator simulator, Parameters* p) } wattrset(win4, COLOR_PAIR(2)); + int maxstrlen = 20; wprintw(win4, " %02d ", simdata->cars[i].pos); - wprintw(win4, " %-20s ", simdata->cars[i].driver); - wprintw(win4, " %-20s ", simdata->cars[i].car); + wprintw(win4, " %-*.*s ", maxstrlen, maxstrlen, simdata->cars[i].driver); + wprintw(win4, " %-*.*s ", maxstrlen, maxstrlen, simdata->cars[i].car); wprintw(win4, " %d ", simdata->cars[i].lap); char clastlap[14];