push
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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){
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,49 @@
|
||||
#include "fossils.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct fossil *init_fossil(char *species, enum body_part body_part, size_t age, char has_wings){
|
||||
|
||||
if(species == NULL) return NULL;
|
||||
|
||||
struct fossil *fossil = malloc(sizeof(struct fossil));
|
||||
if(fossil == NULL)return NULL;
|
||||
|
||||
int index = 0;
|
||||
while(*(species + index) != '\0') index ++;
|
||||
|
||||
fossil->species = malloc((index + 1) * sizeof(char*));
|
||||
if(fossil == NULL){
|
||||
free(fossil);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(fossil->species, species);
|
||||
fossil->part = body_part;
|
||||
fossil->age = age;
|
||||
fossil->has_wings = has_wings;
|
||||
|
||||
return fossil;
|
||||
}
|
||||
|
||||
struct fossil *assemble_wingless(struct fossil *fossils[4]){
|
||||
|
||||
if(fossils == NULL) return NULL;
|
||||
|
||||
for(int i = 0; i < 4; i++){
|
||||
if(fossils[i] == NULL) return NULL;
|
||||
}
|
||||
|
||||
if()
|
||||
/*
|
||||
char *sp = fossils[0]->species;
|
||||
int age = fossils[0]->age;
|
||||
int req = 0;
|
||||
for(int i = 0; i < 4; i++){
|
||||
|
||||
if(fossils[i]->has_wings != 0) return NULL;
|
||||
if(fossils[i]->species != sp && fossils[i]->age == age) return NULL;
|
||||
if((fossils[i]->part != SKULL || fossils[i]->part != ) || req != 1;){}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef FOSSILS_H
|
||||
#define FOSSILS_H
|
||||
#include <stdio.h>
|
||||
|
||||
enum body_part
|
||||
{
|
||||
SKULL,
|
||||
TORSO,
|
||||
TAIL,
|
||||
WINGS,
|
||||
LEGS,
|
||||
COMPLETE,
|
||||
};
|
||||
|
||||
struct fossil{
|
||||
char* species;
|
||||
enum body_part part;
|
||||
size_t age;
|
||||
char has_wings;
|
||||
};
|
||||
|
||||
struct fossil *init_fossil(char *species, enum body_part body_part, size_t age, char has_wings);
|
||||
struct fossil *assemble_wingless(struct fossil *fossils[4]);
|
||||
struct fossil *assemble_with_wings(struct fossil *fossils[5]);
|
||||
struct fossil **assemble_all_fossils(struct fossil **fossils, size_t nb_fossils);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "fossils.h"
|
||||
|
||||
int main()
|
||||
{}
|
||||
int main(){
|
||||
|
||||
struct fossil *f = init_fossil("Human", TORSO, 23, 1);
|
||||
printf("species: %s\n", f->species);
|
||||
printf("part: %d\n", f->part);
|
||||
printf("age: %li\n", f->age);
|
||||
printf("wings: %i\n", f->has_wings);
|
||||
free(f->species);
|
||||
free(f);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user