mat->data = malloc(nbDeLignes*nbDeColonnes*sizeof(*mat->data));
t = malloc(n * sizeof(*t));
printf("Nombre de ligne = %d\n",NBL); printf("Nombre de colonne = %d\n",NBC)
mat->data = malloc(nbDeLignes*nbDeColonnes*sizeof(*mat->data));
/* ERROR */ for(i=0; i< size_Mat; ++i) (mat->data)[i] = i;
for(i=0; i< 2; ++i) (mat->data)[i] = i;
mat->data = malloc(nbDeLignes*nbDeColonnes*sizeof(double)); // initialisation de la matrice for(i=0; i< size_Mat; ++i) mat->data[i] = sqrt(i);
sizeof(double)et ça marche très bien
for(i=0; i< size_Mat; ++i) (mat->data)[i] = i;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#include<stdio.h> const int MAX = 10; int main() { int i; for ( i = 0 ; i < MAX ; ++i ) printf("> %d\n", i); return 0; }
> 0 > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9
12.2 Comment allouer proprement une variable ?
Le plus portable et le plus simple est de faire ainsi :
var_t * ma_var = malloc(N * sizeof *ma_var);
Si le type de la variable change, l'allocation est toujours
valide. À noter que l'on ne caste pas le retour de malloc()
printf("%d ",mat->data[i0*NBC+i1]);
warning: format '%d' expects type 'int', but argument 2 has type 'double'