Fixed for loop where it would not loop over all of the elements in

ships.
This commit is contained in:
Kranklyboy 2018-04-15 21:15:39 +02:00
parent 1fc9d0d29c
commit 97ebb46e6a

View File

@ -202,7 +202,7 @@ static void parse(int argc, char *argv[])
int countLength3 = 0; int countLength3 = 0;
int countLength4 = 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) { if (ships[i]->shipsize == 2) {
countLength2++; countLength2++;
} else if (ships[i]->shipsize == 3) { } else if (ships[i]->shipsize == 3) {
@ -216,9 +216,9 @@ static void parse(int argc, char *argv[])
} }
} }
if (countLength2 != SHIP_CNT_LEN2 || if ((countLength2 != SHIP_CNT_LEN2) ||
countLength3 != SHIP_CNT_LEN3 || (countLength3 != SHIP_CNT_LEN3) ||
countLength4 != SHIP_CNT_LEN4) { (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); 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(); cleanup();
usage(); usage();