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
 
// fonction qui créé le tableau 2 D
float** alloc2d(unsigned int nbligne , unsigned int nbcolonne)
{
    float **tab;
    unsigned int i,j;
    if ((nbligne==00) || (nbcolonne==0))
    {
        tab=NULL;
    }
    else
    {
        tab=(float **)malloc(nbligne*sizeof(float *));
        for(i=0; i<nbligne; i++)
        {
            tab[i]=(float *)malloc(nbcolonne*sizeof(float));
            if(tab[i]== NULL)
            {
                //la création du tableau à échoué je dois libérer la mémoire
                for(j=0; j<i; j++)
                {
                    free(tab[j]);
                }
                tab=NULL;
            }
        }
    }
    return tab;
}
 
//programme principal
int main()
{
    int lig,col;
    float ** tableau;
    lig=200000;
    col=200000;
    tableau=alloc2d(lig,col);
    if (tableau==NULL)
    {
        printf("tableau non crée de taille %d %d \n",lig,col);
    }
    return 0;
}
Bonjour,
Comme le tableau est trop grand, j'ai une erreur de segmentation, j'aimerais qu'il m'affiche "tableau non crée de taille ...."

Yann