I got with working.
Sorry for my poor English.
My goal it was to choose two animals , and need to be the same specie to make a baby.
The baby will weight 20% of the total weight of both parents.
Parents stay with 80%.
Code:
species * birth2animals(species * listoriginal, Area * listareas, int total) {
species *list = listoriginal;
species *list2 = listoriginal;
species buffer;
no *aux, *aux2, bufferanimal;
int id;
int id2;
char son[MAX];
puts("Insert the ID of the parent");
scanf("%d", &id);
getchar();
puts("Insert the ID of the parent 2");
scanf("%d", &id2);
getchar();
puts("What is the name newborn ?");
scanf(" %99{^\n]", son);
getchar();
int parentfind = 0;
int parentfind2 = 0;
// 1 Progenitor
while (list != NULL && parentfind == 0) {
aux = list->listadeanimais;
while (aux != NULL) {
if (aux->id == id) { // Already got the 1 parent
parentfind = 1;
break;
}
aux = aux->prox;
}
// Not to count more species after i found the animal
if (!parentfind) {
list = list->prox;
}
}
// 2 Progenitor
while (list2 != NULL && parentfind2 == 0) {
aux2 = list2->listadeanimais;
while (aux2 != NULL) {
if (aux2->id == id2) { // Already got the 2 parent
parentfind2 = 1;
break;
}
aux2 = aux2->prox;
}
// Not to count more species after i found the animal
if (!parentfind2) {
list2 = list2->prox;
}
}
// Confirmation that you have 2 parents
if (aux == NULL || aux2 == NULL) {
puts("One or two of the IDs does not exist");
return listoriginal;
}
// Now i got the two parents i need to made some verifications.
if (!strcmp(list->especie, list2->especie)) {// Same specie i can continue.
if (!strcmp(aux->nomelocal, aux2->nomelocal)) { // Same area
bufferanimal.peso = ((aux->peso * 0.20) + (aux2->peso * 0.20));
strncpy(buffer.especie, list->especie, MAX);
strncpy(bufferanimal.nomelocal, aux->nomelocal, MAX);
strncpy(bufferanimal.nome, son, MAX);
if (insereanimal(listoriginal, buffer, bufferanimal, listareas, total)) {
aux->peso = aux->peso * 0.80;
aux2->peso = aux2->peso * 0.80;
return listoriginal;
} else {
puts("birth not possible");
// TODO - Repor o peso em caso de falha
return listoriginal;
}
} else {
puts("not in the same local");
return listoriginal;
}
} else {
puts("Not the same specie");
return listoriginal;
}
}