Bonjour,
J'ai fait le code ci dessous qui me permet via une fonction d'initialiser touts les termes de la matrice à zéro ci dessous :
#include <stdio.h>
#include <stdlib.h>
int matrice[2][3] =
{
{1, 2, 3},
{4, 5, 6},
};
void initialisation(int (*pMatrice)[2][3])
{
for(int i = 0; i < 2; i++)
for(int j = 0; j < 3; j++)
*pMatrice[i][j] = 0;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 3; j++)
printf("pMatrice[%d][%d] = %d\n",i, j, *pMatrice[i][j]);
}
int main(void)
{
initialisation(&matrice);
return EXIT_SUCCESS;
}
Maintenant je voudrai faire exactement la même chose mais au lieu de transmettre un pointeur sur matrice à ma fonction j'aimerai lui transmettre un vecteur de pointeur qui me permettrai d'initialiser plusieurs matrice en même temps
J'ai fais le code ci dessous :
#include <stdio.h>
#include <stdlib.h>
typedef int matrice[2][3];
int matrice_pair[2][3] =
{
{0, 2, 4},
{6, 8, 10},
};
int matrice_impair[2][3] =
{
{1, 3, 5},
{7, 9, 11},
};
void initialisation(matrice (*p)[2])
{
for(int i = 0; i < 2; i++)
for(int j = 0; j < 3; j++)
*p[0][i][j] = 0;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 3; j++)
*p[1][i][j] = 0;
for(int i = 0; i < 2; i++)
for(int j = 0; j < 3; j++)
printf("Matrice_0[%d][%d] = %d\n",i, j, *p[0][i][j]);
printf("\n\n");
for(int i = 0; i < 2; i++)
for(int j = 0; j < 3; j++)
printf("Matrice_1[%d][%d] = %d\n",i, j, *p[1][i][j]);
}
int main(void)
{
initialisation(&matrice_pair, &matrice_impair);
return EXIT_SUCCESS;
}
Je comprends rien au erreur du compilateur :rolleyes: