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
| /*main.c*/
void delete(void* data);
char** creation_tableau (unsigned int nbLignes, unsigned int nbColonnes, char* valeurs);
int main {
char valeurs[12] = {'a','b','c','d','e','f','g','h','i','j','k','l'};
char** t1 = creation_tableau (3, 4, valeurs);
char* pT1 = &t1[0][0];
laStructure* s1 = malloc(sizeof(laStructure));
memcpy (s1->data, pT1, sizeof(pT1));
delete (s1->data);
}
void delete(void* data) {
// Je ne sais pas comment faire
}
char** creation_tableau (unsigned int nbLignes, unsigned int nbColonnes, char* valeurs) {
char** tableau = (char**)malloc(sizeof(char*) * nbColonnes);
unsigned int i;
for (i=0 ; i<nbColonnes ; i++) {
tableau[i] = (char*)malloc(sizeof(char) * nbLignes);
}
if (!tableau) { return NULL; }
unsigned int j;
for (j=0 ; j<nbLignes ; j++) {
for (i=0 ; i<nbColonnes ; i++) {
tableau[i][j] = valeurs[i+j*nbColonnes];
}
}
return tableau;
} |
Partager