Commit 56d543e5 authored by a-j.towse's avatar a-j.towse

NewPokemonNode Function created

parent 2a43be28
File added
File added
...@@ -11,42 +11,42 @@ A-J Towse ...@@ -11,42 +11,42 @@ A-J Towse
//Create struct Pokedex with a pointer to head of Pokemon and head of Player //Create struct Pokedex with a pointer to head of Pokemon and head of Player
//Create variable of type Pokedex called pokedex. //Create variable of type Pokedex called pokedex.
typedef struct Pokedex { typedef struct Pokedex {
struct Pokemon *head; struct Pokemon *Pokemonhead;
struct Player *head; struct Player *Playerhead;
struct Pokedex *pokedex; struct Pokedex *pokedex;
}; }Pokedex;
//Create struct PokemonNode with name,type,ability variables //Create struct PokemonNode with name,type,ability variables
//Create variables of type PokemonNode to store next and previous node in DLL //Create variables of type PokemonNode to store next and previous node in DLL
typedef struct PokemonNode { typedef struct PokemonNode {
char name[20]; char name[50];
char type[10]; char type[50];
char ability[30]; char ability[50];
struct PokemonNode *next; struct PokemonNode *next;
struct PokemonNode *prev; struct PokemonNode *prev;
}; }PokemonNode;
//Create struct PlayerNode wiith name, pokemonCount, and an array of pointers to pokemon owned called pokemonList //Create struct PlayerNode wiith name, pokemonCount, and an array of pointers to pokemon owned called pokemonList
//Create variables of type PlayerNode to store next and previous node in DLL //Create variables of type PlayerNode to store next and previous node in DLL
typedef struct PlayerNode { typedef struct PlayerNode {
char name[20]; char name[50];
int pokemonCount; int pokemonCount;
struct PlayerNode *next; struct PlayerNode *next;
struct PlayerNode *prev; struct PlayerNode *prev;
struct PokemonNode pokemonList[]; struct PokemonNode pokemonList[];
}; }PlayerNode;
//Define functions for PokemonNode struct //Define functions for PokemonNode struct
struct PokemonNode *NewPokemonNode(char name, char type, char ability ); struct PokemonNode * NewPokemonNode(char name[], char type[], char ability[] );
void AddPokemonToList(struct Pokedex *pokedex,char name, char type, char ability); void AddPokemonToList(struct Pokedex *pokedex,char name, char type, char ability);
struct PokemonNode *FindPokemon(struct Pokedex pokedex, char name); struct PokemonNode * FindPokemon(struct Pokedex pokedex, char name);
//Define functions for PlayerNode struct //Define functions for PlayerNode struct
struct PlayerNode *NewPlayerNode(char name); struct PlayerNode * NewPlayerNode(char name);
void AddPlayerToList(struct Pokedex *pokedex, char name); void AddPlayerToList(struct Pokedex *pokedex, char name);
struct PlayerNode *FindPlayer(struct Pokedex pokedex, char name); struct PlayerNode * FindPlayer(struct Pokedex pokedex, char name);
//Define functions for other functionality //Define functions for other functionality
void AddPokemonToPlayer(struct Pokedex pokedex, char Playername, char pokemonName); void AddPokemonToPlayer(struct Pokedex pokedex, char Playername, char pokemonName);
...@@ -55,9 +55,27 @@ void DiplayPlayerDetails(struct Pokedex pokedex, char name); ...@@ -55,9 +55,27 @@ void DiplayPlayerDetails(struct Pokedex pokedex, char name);
void ListPokemon(struct Pokedex pokedex); void ListPokemon(struct Pokedex pokedex);
void ListPlayers(struct Pokedex pokedex); void ListPlayers(struct Pokedex pokedex);
//Create NewPokemonNode function - returns variable of type PokemonNode
struct PokemonNode * NewPokemonNode(char name[], char type[], char ability[] ) {
int main () { struct PokemonNode *newNode = NULL; //Create a pointer to a PokemonNode structure, NULL for safety
newNode = malloc(sizeof(struct PokemonNode)); //Assign memory space for PokemonNode
if (newNode != NULL) { //Ensure it exists
strcpy(newNode->name,name); //Set name
strcpy(newNode->type,type); //Set type
strcpy(newNode->ability,ability); //Set ability
newNode->next = NULL; //Set next pointer to NULL
newNode->prev = NULL; //Set prev pointer to NULL
}
return newNode;
}
int main (void) {
NewPokemonNode("Charmander","Fire","FireBallz");
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