From: Jerome Benoit Date: Sun, 26 Feb 2017 11:13:37 +0000 (+0100) Subject: exo1.c: Use VLA array correctly to store integer values and properly initialized it. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=39ba1592dca861839f707facb99d315756650a43;p=TD_C.git exo1.c: Use VLA array correctly to store integer values and properly initialized it. Signed-off-by: Jerome Benoit --- diff --git a/exo1/exo1.c b/exo1/exo1.c index 3425120..eef51db 100644 --- a/exo1/exo1.c +++ b/exo1/exo1.c @@ -54,8 +54,10 @@ void sortArray(int* array, int length) { int main() { int tab_length = 10; - // GCC do not like variable sized array, even with the size variable properly initialized - int tab[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + int tab[tab_length]; + for (int i = 0; i < tab_length; i++) { + tab[i] = 0; + } for (int i = 0; i < tab_length; i++) { printf("Enter integer value at array's index[%d]? ", i);