From: Jérôme Benoit Date: Sun, 12 Mar 2017 20:40:38 +0000 (+0100) Subject: TP 13 exo1: create an array in the main() X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=884e95575f85cb863b53910d203759a5cfc68d81;p=TD_C.git TP 13 exo1: create an array in the main() Signed-off-by: Jérôme Benoit --- diff --git a/TP_13/exo1/lib/array.c b/TP_13/exo1/lib/array.c index 0c56db6..c9a8246 100644 --- a/TP_13/exo1/lib/array.c +++ b/TP_13/exo1/lib/array.c @@ -1,6 +1,6 @@ #include -#include "sort.h" +#include "array.h" int create_tab(int tab[], unsigned tab_size) { tab = malloc(sizeof(unsigned) * tab_size); @@ -17,6 +17,7 @@ void free_tab(int tab[]) { /* we suppose both tab are already created */ static void copy_tab(int src_tab[], int dest_tab[], unsigned min_tab_size, unsigned index_offset) { + /* FIXME: I think it's worth doing some sanity check on the array size */ for (unsigned i = 0; i < min_tab_size; i++) { dest_tab[i + index_offset] = src_tab[i]; } diff --git a/TP_13/exo1/lib/array.h b/TP_13/exo1/lib/array.h index 3bc6573..9c06bc8 100644 --- a/TP_13/exo1/lib/array.h +++ b/TP_13/exo1/lib/array.h @@ -1,6 +1,8 @@ #ifndef ARRAY_H #define ARRAY_H +#include "sort.h" + int create_tab(int tab[], unsigned tab_size); void free_tab(int tab[]); int concat_tab(int tab1[], unsigned tab_size1, int tab2[], unsigned tab_size2, int tab_dest[]); diff --git a/TP_13/exo1/src/main.c b/TP_13/exo1/src/main.c index 315ed33..1b93898 100644 --- a/TP_13/exo1/src/main.c +++ b/TP_13/exo1/src/main.c @@ -1,8 +1,13 @@ #include #include +#include "array.h" +#include "utils.h" + int main() { - printf("Hello world\n"); + int* tab = NULL; + create_tab(tab, 11); + const unsigned tab_size = ARRAY_SIZE(tab); exit(EXIT_SUCCESS); }