From 97ebb46e6aa11dba74f1afc78c4a1e10657d9e93 Mon Sep 17 00:00:00 2001 From: Kranklyboy Date: Sun, 15 Apr 2018 21:15:39 +0200 Subject: [PATCH] Fixed for loop where it would not loop over all of the elements in ships. --- server.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server.c b/server.c index fcb586d..3ac5a3d 100644 --- a/server.c +++ b/server.c @@ -202,7 +202,7 @@ static void parse(int argc, char *argv[]) int countLength3 = 0; int countLength4 = 0; - for (int i = 0; i < sizeof(ships)/sizeof(struct Ship); i++) { + for (int i = 0; i < 6; i++) { if (ships[i]->shipsize == 2) { countLength2++; } else if (ships[i]->shipsize == 3) { @@ -216,9 +216,9 @@ static void parse(int argc, char *argv[]) } } - if (countLength2 != SHIP_CNT_LEN2 || - countLength3 != SHIP_CNT_LEN3 || - countLength4 != SHIP_CNT_LEN4) { + if ((countLength2 != SHIP_CNT_LEN2) || + (countLength3 != SHIP_CNT_LEN3) || + (countLength4 != SHIP_CNT_LEN4)) { fprintf(stderr, "[%s]: There must be exactly 2 ships of length 2, 3 ships of length 3 and 1 ship of length 4!\n", pname); cleanup(); usage();