Salut à tous
j'ai le code suivant
ce que je veux c'est récupérer dans la fonction main() les données saisies dans numbers
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 #include <stdio.h> #include <stdlib.h> void test2(int *numbers, int *count, int n) { do { scanf ("%d", &numbers[*count]); if(numbers[*count] != 0) { *count = *count + 1; numbers = (int*) realloc (numbers, (*count+1) * sizeof(int)); if (numbers!=NULL) printf("ok "); else { free (numbers); puts ("Error (re)allocating memory"); exit (1); } } } while (numbers[*count] != 0); printf ("\nin Numbers entered: "); for (n=0;n<*count;n++) printf ("%d ",numbers[n]); } int main () { int input,n; int count=0; int * numbers = NULL; printf ("Enter an integer value (0 to end): "); numbers = calloc(1, sizeof(int)); test2(numbers, &count, n); printf ("\nout Numbers entered: "); for (n=0;n<count;n++) printf ("%d ", numbers[n]); free (numbers); printf("\n\n"); system("pause"); return 0; }
Partager