From: Jérôme Benoit Date: Sat, 1 Apr 2017 11:09:28 +0000 (+0200) Subject: TP_13 exo2: use C99 struct initializers X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9c2b41f4a3539f1087e5560d8ceb301978f8a55b;p=TD_C.git TP_13 exo2: use C99 struct initializers Signed-off-by: Jérôme Benoit --- diff --git a/TP_13/exo2/lib/coordinates.c b/TP_13/exo2/lib/coordinates.c index 3aaadd4..ef80ba9 100644 --- a/TP_13/exo2/lib/coordinates.c +++ b/TP_13/exo2/lib/coordinates.c @@ -18,18 +18,13 @@ #include "coordinates.h" -void init_coordinates(coordinates_t* coordinates_array) { +void zero_coordinates(coordinates_t* coordinates_array) { for (unsigned i = 0; i < MAX_COORDINATES; i++) { coordinates_array[i] = set_coordinates(0, 0, 0); } } -void reinit_coordinates(coordinates_t* coordinates_array) { - - init_coordinates(coordinates_array); -} - coordinates_t set_coordinates(int y, int x, unsigned type) { coordinates_t new_coordinates; diff --git a/TP_13/exo2/lib/coordinates.h b/TP_13/exo2/lib/coordinates.h index e236e3b..c549d2e 100644 --- a/TP_13/exo2/lib/coordinates.h +++ b/TP_13/exo2/lib/coordinates.h @@ -30,8 +30,7 @@ typedef struct coordinates_s { unsigned type; /* 0 = O, 1 = X */ } coordinates_t; -void init_coordinates(coordinates_t* coordinates_array); -void reinit_coordinates(coordinates_t* coordinates_array); +void zero_coordinates(coordinates_t* coordinates_array); coordinates_t set_coordinates(int y, int x, unsigned type); unsigned add_coordinates(coordinates_t new_coordinates, coordinates_t* coordinates_array, unsigned round); bool chk_win_conditions(coordinates_t* coordinates_array, unsigned round); diff --git a/TP_13/exo2/src/main.c b/TP_13/exo2/src/main.c index d57be23..854ddb9 100644 --- a/TP_13/exo2/src/main.c +++ b/TP_13/exo2/src/main.c @@ -22,8 +22,17 @@ int main() { curs_set(0); /* array of the active coordinates in the entered order */ - coordinates_t coordinates_array[MAX_COORDINATES]; - init_coordinates(coordinates_array); + coordinates_t coordinates_array[MAX_COORDINATES] = { + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0} + }; coordinates_t new_coordinates = {0, 0, 0}; /* center base coordinates for the board */ @@ -130,7 +139,7 @@ int main() { round = 0; player = 0; errno = 0; - reinit_coordinates(coordinates_array); + zero_coordinates(coordinates_array); winning_condition = false; loop_exit_condition = false; clear();