Bonjour,

J'ai un programme dans lequel je déclare des matrices que je passe ensuite en paramètres à une fonction.
La matrice est allouée dans la fonction.
Mais le problème est que je ne récupère pas les valeurs mises dans la matrice dans le main.

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
 
int main(int argc, char* argv[])
{
    unsigned short int** matrice;
    unsigned short int* tab;
    unsigned short int taille;
 
    init(&matrice, &tab, &taille);
 
    for(int i = 0; i < taille; i ++)
    {
        for(int j = 0; j < taille; j ++)
        {
            printf("[%d][%d]", matrice[i][j]);
        }
        printf("(%d)\n", tab[i]);
    }
}
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
 
 
// int nbElement = est récupéré par lecture d'un fichier
 
int init(unsigned short int** *mat,
         unsigned short int* *tab,
         unsigned short int *taille)
{
   *mat = malloc(nbElement * sizeof(unsigned short int*));
    for(int i = 0; i < nbElement; i ++)
    {
        mat[i] = calloc(nbElement, sizeof(unsigned short int));
        for(int j = 0; j < nbElement; j ++)
        {
            mat[i][j] = 999;
        }
    }
 
    *tab = calloc(nbElement, sizeof(unsigned short int));
 
    *taille = nbElement;
 
    // lecture d'un fichier
    while(fgets(chaine, TAILLE_MAX, fichier) != NULL)
    {
        if(atoi(chaine) > 50) tab[atoi(chaine)] = 1;
        mat[atoi(chaine)][atoi(chaine)] = 15;
    }
}
J'ai simplifier le code, ainsi ce que fait le programme ne veut rien dire ...

Pourriez-vous m'aider ?
Merci :)