if (headP == NULL) // if failed to allocate in memory -> exit.
{
printf("Memory allocation failed. Exiting...");
exit(0);
}
/* setting value of 6 pokemons each in a different node */
PokemonNode PokemonNode1;
PokemonNode* PokemonNode1ptr;
PokemonNode1ptr= &PokemonNode1;
strcpy(PokemonNode1.Name, "\tPikachu");
strcpy(PokemonNode1.Type, "\tElectric");
strcpy(PokemonNode1.Ability, "Static\n");
headP -> next = PokemonNode1ptr;
PokemonNode PokemonNode2;
PokemonNode* PokemonNode2ptr;
PokemonNode2ptr= &PokemonNode2;
strcpy(PokemonNode2.Name, "Clefairy");
strcpy(PokemonNode2.Type, "Fairy");
strcpy(PokemonNode2.Ability, "\tCuteCharm\n");
PokemonNode1ptr -> next = PokemonNode2ptr;
PokemonNode PokemonNode3;
PokemonNode* PokemonNode3ptr;
PokemonNode3ptr= &PokemonNode3;
strcpy(PokemonNode3.Name, "\tVulpix");
strcpy(PokemonNode3.Type, "\tFire");
strcpy(PokemonNode3.Ability, "\tFlash Fire\n");
PokemonNode2ptr -> next = PokemonNode3ptr;
PokemonNode PokemonNode4;
PokemonNode* PokemonNode4ptr;
PokemonNode4ptr= &PokemonNode4;
strcpy(PokemonNode4.Name, "\tWigglyTuff");
strcpy(PokemonNode4.Type, "Fairy");
strcpy(PokemonNode4.Ability, "\tCompetitive\n");
PokemonNode3ptr -> next = PokemonNode4ptr;
PokemonNode PokemonNode5;
PokemonNode* PokemonNode5ptr;
PokemonNode5ptr= &PokemonNode5;
strcpy(PokemonNode5.Name, "\tMeowth");
strcpy(PokemonNode5.Type, "\tNormal");
strcpy(PokemonNode5.Ability, "\tTechnician\n");
PokemonNode4ptr -> next = PokemonNode5ptr;
PokemonNode PokemonNode6;
PokemonNode* PokemonNode6ptr;
PokemonNode6ptr= &PokemonNode6;
strcpy(PokemonNode6.Name, "\tPonyta");
strcpy(PokemonNode6.Type, "\tFire");
strcpy(PokemonNode6.Ability, "\tRun Away\n");
PokemonNode5ptr -> next = PokemonNode6ptr;
PokemonNode6ptr -> next = NULL;
PlayerNode *headPlr = NULL; //new empty list is created (PlayerNode), with a head node of 0 value.
headPlr = malloc(sizeof(PlayerNode)); // setting space for PlayerNode structure.
if (headPlr == NULL) // if failed to allocate in memory -> exit.
{
printf("Memory allocation failed. Exiting...");
exit(0);
}
/* setting value of 3 players in different nodes*/
PlayerNode PlayerNode1;
PlayerNode* PlayerNode1ptr;
PlayerNode1ptr= &PlayerNode1;
strcpy(PlayerNode1.Username, "\tElise");
PlayerNode1.PokemonOwned=2;
headPlr -> next = PlayerNode1ptr;
PlayerNode PlayerNode2;
PlayerNode* PlayerNode2ptr;
PlayerNode2ptr= &PlayerNode2;
strcpy(PlayerNode2.Username, "\tIvan");
PlayerNode2.PokemonOwned=2;
PlayerNode1ptr -> next = PlayerNode2ptr;
PlayerNode PlayerNode3;
PlayerNode* PlayerNode3ptr;
PlayerNode3ptr= &PlayerNode3;
strcpy(PlayerNode3.Username, "\tZoya");
PlayerNode3.PokemonOwned=1;
PlayerNode2ptr -> next = PlayerNode3ptr;
PlayerNode3ptr -> next = NULL;
printf("\t\t\t\t\t\tWelcome to Pokedex\n\n\n What would you like to display? (Enter corresponding number)\n\n \t1)Pokemon list\n\n\t2)Player List\n\n");
int userinp1;
scanf("%d", &userinp1);
if (userinp1 == 1) {
printf(" \n\nPokemons registered:\t" );
ListPokemon (headP);
printf("\n\nEnter one of the following numbers");
printf("\n\n1.To display a Pokemon's details.");
printf("\n\n2.To add a new pokemon.");
printf("\n\n3.Exit.\n\n");
int userinp2;
scanf("%d", &userinp2);
if (userinp2 == 1){
char search[20];
DisplayPokemonDetails(headP);
printf("\n\n");
}
else if (userinp2 == 2){
printf("\n\n");
char Name[20], Type[10], Ability[20];
printf("enter name : ");
scanf("%s", Name);
printf("enter type : ");
scanf("%s", Type);
printf("enter ability : ");
scanf("%s", Ability);
AddPokemonToList();
}
else {
printf("Exiting...");
}
}
else if (userinp1 == 2){
printf("\n\nPlayers registered:\t");
ListPlayer(headPlr);
printf("\n\nEnter one of the following numbers.");