Commit 8089bc5e authored by steven.mappin's avatar steven.mappin

Upload New File

parent ced6807a
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//pokemon struct
typedef struct PokeNode {
char* name;
char* type;
char* ability;
int dex_num;
struct PokeNode *next;
} PokeNode;
//player struct
typedef struct {
char* name;
char* Pname;
int Powned;
} Player;
typedef struct Pokedex{
Player *Playerhead;
PokeNode *PokeHead;
}Pokedex;
// initializing each list
PokeNode *newPokeNode(char name, char type, char ability, int dex_num);
void AddNodeToStartOfList(PokeNode **ptr_to_start, char name[20], char type[20], char ability[20], int dex_num);
void AddPokemonToList(PokeNode **ptr_to_start, char name[20], char type[20], char ability[20], int dex_num);
void PrintLinkedList(PokeNode *start);
// main storing
int main() {
PokeNode *head = NULL;
AddNodeToStartOfList(&head,"Bulbasaur","Grass","Thick Fat",1);
AddPokemonToList(&head,"Squirtel","Water","Torrent",6);
AddPokemonToList(&head, "Charmander","Fire","Blaze",4);
PrintLinkedList(head);
// array of my players struct
Player players[4] = {
{ .name = "Ash", .Powned = 6, .Pname = "Pikachu - Blaustoise - Charizard - Butterfree - Pidgeotto - Venosaur"},
{ .name = "Misty", .Powned = 2, .Pname = "Starmie - Golduck"},
{ .name = "Dawn", .Powned = 3, .Pname = "Piplup - Togekiss - Mamoswine"},
{ .name = "Red", .Powned = 5, .Pname = "Pikachu - Blaustoise - Charzard - Laprass - Snorlax"}
};
for (int pokedex = 0; pokedex < sizeof(players)/sizeof(Player); pokedex++)
{
printf("Trainer Name: %s\nNumber of Pokemon: %d\nList of Pokemon: %s\n", players[pokedex].name, players[pokedex].Powned, players[pokedex].Pname);
}
return 0;
}
// setting aside memory for pokenode
PokeNode *newPokeNode(char name, char type, char ability, int dex_num) {
PokeNode *new_node = NULL;
new_node = malloc(sizeof(PokeNode));
if (new_node != NULL) {
new_node->name = &name;
new_node->type = &type;
new_node->ability = &ability;
new_node->dex_num = dex_num;
new_node->next = NULL;
}
return new_node;
}
//adding a pokemon to the start of the list and setting aside memory in the heap for it.
void AddNodeToStartOfList(PokeNode **ptr_to_start, char name[], char type[], char ability[], int dex_num) {
struct PokeNode *temp = (struct PokeNode*) malloc(sizeof(struct PokeNode));
temp->name = name;
temp->type = type;
temp->ability = ability;
temp->dex_num = dex_num;
temp->next = NULL;
*ptr_to_start = temp;
}
// creating the print for the linked list and setting the layout of the way it prints
void PrintLinkedList(PokeNode *start) {
while (start != NULL) {
printf("Pokemon's Name - %s\n", start->name);
printf("Pokemon's Type - %s\n", start->type);
printf("Pokemon's Ability - %s\n", start->ability);
printf("Pokemon's Pokedex Number - %03d\n", start->dex_num);
start = start->next;
}
}
//pokemon pointers to the struct and to set memory aside in the heap
void AddPokemonToList(PokeNode **ptr_to_start, char name[], char type[], char ability[], int dex_num) {
struct PokeNode *new_node = (struct PokeNode*) malloc(sizeof(struct PokeNode));
new_node->name = name;
new_node->type = type;
new_node->ability = ability;
new_node->dex_num = dex_num;
new_node->next = NULL;
PokeNode *temp = *ptr_to_start;
if (*ptr_to_start == NULL) {
*ptr_to_start = new_node;
return;
}
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = new_node;
return;
}
//funtion to find a pokemon
void FindPokemon(PokeNode *start, char *name){
while (start != NULL) {
if(name == start->name){
printf("pointer address; %p", &start);
exit(0);
};
start = start->next;
}
printf ("pokemon doesnt exist");
}
\ No newline at end of file
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