Bonjour,
Je voudrais créer dynamiquement un tableau de 500 mots, chaque mot ayant une taille de 100 char.
En gros c'est un tableau à deux dimension (donc char**).
Ce que je faisai c'était:
Est ce correct?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 char **monTableau = NULL; *monTableau = (char *) calloc(500, sizeof(char)); for(int i = 0; i < 100; i++) monTableau[i] = (char *) calloc(100, sizeof(char));
Ensuite je veux ecrire des mots dans ce tableau donc je fais:
Etes vous d'accord?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 char monMots[100] = "hello world!"; for(int i = 0; i < 500; i++) memcpy( &monTableau[i] , monMots, 100 * sizeof(char));
Je vous remercie
Partager