Commit 556f2259 authored by a-j.towse's avatar a-j.towse

working Add and find pokemon

parent 8916b496
No preview for this file type
...@@ -90,12 +90,14 @@ void AddPokemonToList(struct Pokedex pokedex,char name[], char type[], char abil ...@@ -90,12 +90,14 @@ void AddPokemonToList(struct Pokedex pokedex,char name[], char type[], char abil
} }
/*while (temp->next != NULL) { while (temp->next != NULL) {
//If pokemon already exists in the list, do nothiing //If pokemon already exists in the list, do nothiing
if (strcmp(temp->name,newNode->name) == 0) { if (strcmp(temp->name,newNode->name) == 0) {
return; return;
} }
}*/ temp = temp->next;
printf("%s\n",temp->name);
}
temp->next = newNode; //Set the next pointer of the old last node to new node temp->next = newNode; //Set the next pointer of the old last node to new node
newNode->prev = temp; //Set the prev pointer of the new node to the old last node newNode->prev = temp; //Set the prev pointer of the new node to the old last node
...@@ -105,13 +107,15 @@ void AddPokemonToList(struct Pokedex pokedex,char name[], char type[], char abil ...@@ -105,13 +107,15 @@ void AddPokemonToList(struct Pokedex pokedex,char name[], char type[], char abil
struct PokemonNode * FindPokemon(struct Pokedex pokedex, char name[]) { struct PokemonNode * FindPokemon(struct Pokedex pokedex, char name[]) {
PokemonNode *temp = pokedex.ptrToPokemonHead; PokemonNode **ptrHead = pokedex.ptrToPokemonHead;
PokemonNode *temp = *ptrHead;
while (temp->next != NULL) { while (temp != NULL) {
if (strcmp(temp->name,name) == 0) { if (strcmp(temp->name,name) == 0) {
return temp; return temp;
} }
temp = temp->next;
} }
} }
...@@ -130,6 +134,7 @@ int main (void) { ...@@ -130,6 +134,7 @@ int main (void) {
//NewPokemonNode("Charmander","Fire","FireBallz"); //NewPokemonNode("Charmander","Fire","FireBallz");
AddPokemonToList(pokedex,"Charmander","Fire","FireBallz"); AddPokemonToList(pokedex,"Charmander","Fire","FireBallz");
AddPokemonToList(pokedex,"Squirtle","Water","WaterBlast"); AddPokemonToList(pokedex,"Squirtle","Water","WaterBlast");
//printf("%p\n",FindPokemon(pokedex,"Charmander"));
printf("%p\n",FindPokemon(pokedex,"Squirtle"));
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment