This commit is contained in:
2026-02-13 18:37:24 +01:00
parent b646f5ca78
commit eae4adab35
10 changed files with 97 additions and 10 deletions
Binary file not shown.
+1 -1
View File
@@ -45,7 +45,7 @@ struct animal *animal_from_fish(const char *color, struct fish *fish){
}
strcpy(animal->color, color);
animal->type = 1;
animal->type = FISH;
/*
union animals *animals = malloc(sizeof(union animals));
if(animals == NULL){
+1 -1
View File
@@ -44,7 +44,7 @@ struct animal *animal_from_insect(const char *color, struct insect *insect){
}
strcpy(animal->color, color);
animal->type = 0;
animal->type = INSECT;
animal->animal.insect = insect;
return animal;
}
+7 -5
View File
@@ -36,7 +36,7 @@ struct vector *vector_append(struct vector *v, struct animal *animal){
if (v->capacity <= v->size) v = vector_resize(v, v->capacity * 2);
// TODO A voir si le realloc ajoute de l'espace a gauche ou a droite
// car sinon y a ecrasement de data
*(v->animal + (v->capacity - v->size )) = animal;
v->animal[v->size] = animal;
v->size ++;
return v;
}
@@ -46,10 +46,12 @@ void free_animal(struct animal *animal){
if (animal == NULL) return;
//if(animal->color != NULL) free(animal->color);
printf("%s\n",animal->animal.fish->species);
printf("%s\n", animal->animal.insect->species);
if(animal->type == INSECT) free_insect(animal->animal.insect);
if(animal->type == FISH) free_fish(animal->animal.fish);
//printf("%s\n",animal->animal.fish->species);
//printf("%s\n", animal->animal.insect->species);
if(animal->type == INSECT)
free_insect(animal->animal.insect);
if(animal->type == FISH)
free_fish(animal->animal.fish);
free(animal->color);
free(animal);
}