Fixed for loop where it would not loop over all of the elements in
ships.
This commit is contained in:
parent
1fc9d0d29c
commit
97ebb46e6a
8
server.c
8
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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user