Bonjour,
Je chercher à savoir comment allouer un tableau de type :Mais je n'y arrive pas. Par exemple je voudrais avoir 10 tableaux t[20].Code:char *t[20];
Merci d'avance.
Version imprimable
Bonjour,
Je chercher à savoir comment allouer un tableau de type :Mais je n'y arrive pas. Par exemple je voudrais avoir 10 tableaux t[20].Code:char *t[20];
Merci d'avance.
Salut,
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #include <stdlib.h> int main(void) { char (*t)[20]; /* Alloue 10 tableaux de 20 char */ t = malloc(10 * sizeof(*t)); /* ... */ free(t); return 0; }
Un petit truc du genre:
typedef char mon_type[20];
mon_type* p_tableau = NULL;
puis, dans ton programme:
p_tableau = (mon_type*) malloc ( sizeof ( mon_type ) * 10 );
et à la destrruction:
free ( p_tableau );
p_tableau = NULL;