From: Jérôme Benoit Date: Mon, 27 Feb 2017 18:24:46 +0000 (+0100) Subject: TP 8 exo1: be more explicit about the malloc size. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=db8e62608ddedc008ae2bba9edb7d5d03317f0a8;p=TD_C.git TP 8 exo1: be more explicit about the malloc size. Signed-off-by: Jérôme Benoit --- diff --git a/TP_8/exo1/exo1.c b/TP_8/exo1/exo1.c index b10155c..beea2f6 100644 --- a/TP_8/exo1/exo1.c +++ b/TP_8/exo1/exo1.c @@ -11,14 +11,15 @@ int main() { int* arr; printf("Longeur?\n"); int size = promptValue(); - arr = malloc(sizeof(arr[size])); + //arr = malloc(sizeof(arr[size])); + arr = malloc(sizeof(int)*size); for (int i = 0; i < size; i++) { printf("Valeur?\n"); arr[i] = promptValue(); } - printf("Sortie\n"); + printf("Sortie:\n"); int sum = 0; for (int i = 0; i < size; i++) { printf("%d (%d)\n", arr[i], sum += arr[i]);