Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
c_pokedex_assignment
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
elijah vasquez
c_pokedex_assignment
Commits
8e533737
Commit
8e533737
authored
Jan 17, 2023
by
elijah vasquez
🦍
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
idkanymore
parent
99d556d8
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
152 deletions
+57
-152
functions.exe
functions.exe
+0
-0
functions.h
functions.h
+17
-17
liststructure.c
liststructure.c
+7
-6
main.c
main.c
+33
-129
main.exe
main.exe
+0
-0
No files found.
functions.exe
View file @
8e533737
No preview for this file type
functions.h
View file @
8e533737
// Structs and functions placed here
// Structs and functions placed here
// Pokemon List
// Pokemon List
typedef
struct
PokemonNode
typedef
struct
PokemonNode
// typedef struct to create alias for data type
{
{
// in combination with struct for struct type
char
name
[
20
];
char
name
[
20
];
// kept at 20 as pokemon names don't exceed higher than value
char
type
[
20
];
char
type
[
20
];
char
ability
[
30
];
char
ability
[
30
];
struct
PokemonNode
*
next
;
struct
PokemonNode
*
next
;
// used for traversing singly linked list from pokemon
}
PokemonNode
;
}
PokemonNode
;
// Player List
// Player List
typedef
struct
PlayerNode
typedef
struct
PlayerNode
// Player node will include name, pokemon owned and is placed
{
{
// in an array
char
name
[
50
];
char
name
[
50
];
int
totalPokemon
;
int
totalPokemon
;
// total number of pokemon owned by players
PokemonNode
*
PokemonArray
[
20
];
//Array of players
PokemonNode
*
PokemonArray
[
20
];
//
Array of players
struct
PlayerNode
*
next
;
struct
PlayerNode
*
next
;
// used for traversing singly linked list
}
PlayerNode
;
}
PlayerNode
;
// Pokedex structure
// Pokedex structure
typedef
struct
Pokedex
typedef
struct
Pokedex
// To house the header nodes to start single linked lists
{
{
PokemonNode
*
pokeHead
;
PokemonNode
*
pokeHead
;
// pokemon node used to create head pointer variable
PlayerNode
*
playerHead
;
PlayerNode
*
playerHead
;
//player node used to create head pointer variable
}
Pokedex
;
}
Pokedex
;
// Pokemon List
functions
// Pokemon List
PokemonNode
*
NewPokemonNode
(
char
name
[
20
],
char
type
[
20
],
char
ability
[
30
]);
PokemonNode
*
NewPokemonNode
(
char
name
[
20
],
char
type
[
20
],
char
ability
[
30
]);
void
AddPokemonToList
(
Pokedex
*
pokedex
,
char
name
[
20
],
char
type
[
20
],
char
ability
[
30
]);
void
AddPokemonToList
(
Pokedex
*
pokedex
,
char
name
[
20
],
char
type
[
20
],
char
ability
[
30
]);
PokemonNode
*
FindPokemon
(
Pokedex
*
pokedex
,
char
name
[
20
]);
PokemonNode
*
FindPokemon
(
Pokedex
*
pokedex
,
char
name
[
20
]);
// Player List
functions
// Player List
PlayerNode
*
NewPlayerNode
(
char
name
[
50
]);
// Create new node, return pointer to node
PlayerNode
*
NewPlayerNode
(
char
name
[
50
]);
// Create new node, return pointer to node
void
AddPlayerToList
(
Pokedex
*
pokedex
,
char
name
[
50
]);
// Check if name already exists in Player list.
void
AddPlayerToList
(
Pokedex
*
pokedex
,
char
name
[
50
]);
// Check if name already exists in Player list.
PlayerNode
*
FindPlayer
(
Pokedex
*
pokedex
,
char
name
[
50
]);
// Searches Player list for name.
PlayerNode
*
FindPlayer
(
Pokedex
*
pokedex
,
char
name
[
50
]);
// Searches Player list for name.
void
AddPokemonToPlayer
(
Pokedex
*
player
,
Pokedex
*
pokemon
,
char
playerName
[
50
],
char
pokemonName
[
20
]);
// Adds Pokemon to player's Pokemon list
void
AddPokemonToPlayer
(
Pokedex
*
player
,
Pokedex
*
pokemon
,
char
playerName
[
50
],
char
pokemonName
[
20
]);
// Adds Pokemon to player's Pokemon list
// Additional
functions for the pokedex
// Additional
// Pokemon details
functs
// Pokemon details
void
DisplayPokemonDetails
(
Pokedex
*
pokedex
,
char
name
[
20
]);
// Output details of pokemon
void
DisplayPokemonDetails
(
Pokedex
*
pokedex
,
char
name
[
20
]);
// Output details of pokemon
PokemonNode
*
ListPokemon
(
Pokedex
*
pokedex
);
//output list of names of all POKEMON in pokedex
PokemonNode
*
ListPokemon
(
Pokedex
*
pokedex
);
//output list of names of all POKEMON in pokedex
// Pokemon players
functs
// Pokemon players
void
DisplayPlayerDetails
(
Pokedex
*
pokedex
,
char
name
[
50
]);
// output details of players, incl. list of names of pokemon owned
void
DisplayPlayerDetails
(
Pokedex
*
pokedex
,
char
name
[
50
]);
// output details of players, incl. list of names of pokemon owned
PlayerNode
*
ListPlayers
(
Pokedex
*
pokedex
);
//output list of names of all PLAYERS in pokedex
PlayerNode
*
ListPlayers
(
Pokedex
*
pokedex
);
//output list of names of all PLAYERS in pokedex
liststructure.c
View file @
8e533737
// Calling of functions and setting up nodes
// Calling of functions and setting up nodes
#include "functions.h"
#include "functions.h"
int
main
(
void
)
{
// Adding Pokemon to list
int
main
(
void
)
{
// Adding Pokemon nodes to list
Pokedex
*
pokeHead
=
NewPokemonNode
(
"blastoise"
,
"water"
,
"torrent"
);
//Creation of node to introduce head of single linked list
Pokedex
*
pokeHead
=
NewPokemonNode
(
"blastoise"
,
"water"
,
"torrent"
);
//Creation of node to introduce head of single linked list
AddPokemonToList
(
pokeHead
,
"dragapult"
,
"dragon"
,
"infiltrator"
);
AddPokemonToList
(
pokeHead
,
"dragapult"
,
"dragon"
,
"infiltrator"
);
AddPokemonToList
(
pokeHead
,
"volcarona"
,
"fire"
,
"flame body"
);
AddPokemonToList
(
pokeHead
,
"volcarona"
,
"fire"
,
"flame body"
);
AddPokemonToList
(
pokeHead
,
"regieleki"
,
"electric"
,
"transistor"
);
AddPokemonToList
(
pokeHead
,
"regieleki"
,
"electric"
,
"transistor"
);
// Adding player to player list
// Adding player
nodes
to player list
Pokedex
*
playerHead
=
NewPlayerNode
(
"armin"
);
Pokedex
*
playerHead
=
NewPlayerNode
(
"armin"
);
AddPlayerToList
(
playerHead
,
"chase"
);
AddPlayerToList
(
playerHead
,
"chase"
);
AddPlayerToList
(
playerHead
,
"ziggy"
);
AddPlayerToList
(
playerHead
,
"ziggy"
);
//
Adding pokemon to player
//
Linking pokemon with players
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"armin"
,
"blastoise"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"armin"
,
"blastoise"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"armin"
,
"dragapult"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"armin"
,
"dragapult"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"chase"
,
"volcarona"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"chase"
,
"volcarona"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"ziggy"
,
"regieleki"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"ziggy"
,
"regieleki"
);
//
To display all of both pokemon and players
//
Displays and lists all pokemon and players present in program
ListPokemon
(
pokeHead
);
ListPokemon
(
pokeHead
);
ListPlayers
(
playerHead
);
ListPlayers
(
playerHead
);
...
@@ -35,3 +35,4 @@ int main(void)
...
@@ -35,3 +35,4 @@ int main(void)
DisplayPokemonDetails
(
pokeHead
,
"volcarona"
);
DisplayPokemonDetails
(
pokeHead
,
"volcarona"
);
DisplayPokemonDetails
(
pokeHead
,
"regieleki"
);
DisplayPokemonDetails
(
pokeHead
,
"regieleki"
);
}
}
main.c
View file @
8e533737
// Main file, RUN FROM HERE!!!
#include <stdbool.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -5,16 +6,16 @@
...
@@ -5,16 +6,16 @@
#include "liststructure.c"
#include "liststructure.c"
// Details of Pokemon
// Details of Pokemon
void
DisplayPokemonDetails
(
Pokedex
*
pokedex
,
char
name
[
5
0
])
{
void
DisplayPokemonDetails
(
Pokedex
*
pokedex
,
char
name
[
2
0
])
{
PokemonNode
*
headPoke
=
pokedex
;
PokemonNode
*
headPoke
=
pokedex
;
while
(
headPoke
!=
NULL
)
{
while
(
headPoke
!=
NULL
)
{
if
(
strcmp
(
headPoke
->
name
,
name
)
==
0
)
{
if
(
strcmp
(
headPoke
->
name
,
name
)
==
0
)
{
printf
(
"
\n
POKEMON DETAILS
\n
name: %s
\n
"
,
headPoke
->
name
);
printf
(
"
\n
POKEMON DETAILS
\n
name: %s
\n
"
,
headPoke
->
name
);
printf
(
"type: %s
\n
"
,
headPoke
->
type
);
printf
(
"type: %s
\n
"
,
headPoke
->
type
);
printf
(
"primary ability: %s
\n
"
,
headPoke
->
ability
);
printf
(
"primary ability: %s
\n
"
,
headPoke
->
ability
);
return
;
return
;
}
}
headPoke
=
headPoke
->
next
;
headPoke
=
headPoke
->
next
;
}
}
}
}
...
@@ -53,8 +54,8 @@ PlayerNode* ListPlayers(Pokedex* pokedex) {
...
@@ -53,8 +54,8 @@ PlayerNode* ListPlayers(Pokedex* pokedex) {
return
playerHead
;
return
playerHead
;
}
}
// Create
s a new pokemon node and returns a pointer to said node
// Create
new pokemon node, return pointer to it
PokemonNode
*
NewPokemonNode
(
char
name
[
50
],
char
type
[
50
],
char
ability
[
5
0
])
{
PokemonNode
*
NewPokemonNode
(
char
name
[
20
],
char
type
[
20
],
char
ability
[
3
0
])
{
PokemonNode
*
newPoke
=
NULL
;
PokemonNode
*
newPoke
=
NULL
;
newPoke
=
malloc
(
sizeof
(
PokemonNode
));
newPoke
=
malloc
(
sizeof
(
PokemonNode
));
...
@@ -67,9 +68,8 @@ PokemonNode* NewPokemonNode(char name[50], char type[50], char ability[50]) {
...
@@ -67,9 +68,8 @@ PokemonNode* NewPokemonNode(char name[50], char type[50], char ability[50]) {
return
newPoke
;
return
newPoke
;
}
}
// Checks if Pokemon name already exists, if not a new node is created
// If pokemon exists check
void
AddPokemonToList
(
Pokedex
*
pokedex
,
char
name
[
20
],
char
type
[
20
],
void
AddPokemonToList
(
Pokedex
*
pokedex
,
char
name
[
20
],
char
type
[
20
],
char
ability
[
50
])
{
char
ability
[
50
])
{
PokemonNode
*
ptr
=
pokedex
;
PokemonNode
*
ptr
=
pokedex
;
bool
exists
=
false
;
bool
exists
=
false
;
while
(
ptr
->
next
!=
NULL
)
{
while
(
ptr
->
next
!=
NULL
)
{
...
@@ -86,8 +86,8 @@ void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20],
...
@@ -86,8 +86,8 @@ void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20],
}
}
// Searches Pokemon List for name, if the name is not found NULL is returned
// Searches Pokemon List for name, if the name is not found NULL is returned
PokemonNode
*
FindPokemon
(
Pokedex
*
pokedex
,
char
name
[
20
])
{
PokemonNode
*
FindPokemon
(
Pokedex
*
pokedex
,
char
name
[
20
])
{
PokemonNode
*
pointer
=
pokedex
;
PokemonNode
*
pointer
=
pokedex
;
while
(
pointer
!=
NULL
)
{
while
(
pointer
!=
NULL
)
{
if
(
strcmp
(
pointer
->
name
,
name
)
==
0
)
{
if
(
strcmp
(
pointer
->
name
,
name
)
==
0
)
{
return
pointer
;
return
pointer
;
...
@@ -98,76 +98,21 @@ PokemonNode *FindPokemon(Pokedex *pokedex, char name[20]) {
...
@@ -98,76 +98,21 @@ PokemonNode *FindPokemon(Pokedex *pokedex, char name[20]) {
}
}
// Creates a new player node and returns a pointer to said node
// Creates a new player node and returns a pointer to said node
PlayerNode
*
NewPlayerNode
(
char
name
[
50
])
{
PlayerNode
*
NewPlayerNode
(
char
name
[
50
])
{
PlayerNode
*
new_player
=
NULL
;
PlayerNode
*
playerNew
=
NULL
;
new_player
=
malloc
(
sizeof
(
PlayerNode
));
playerNew
=
malloc
(
sizeof
(
PlayerNode
));
if
(
new_player
!=
NULL
)
{
if
(
playerNew
!=
NULL
)
{
strcpy
(
new_player
->
name
,
name
);
strcpy
(
playerNew
->
name
,
name
);
new_player
->
totalPokemon
=
0
;
playerNew
->
totalPokemon
=
0
;
new_player
->
next
=
NULL
;
playerNew
->
next
=
NULL
;
}
}
return
new_player
;
return
playerNew
;
}
}
// Checks if Player name already exists, if not a new node is created
// Checks if Player name already exists, if not a new node is created
void
AddPlayerToList
(
Pokedex
*
pokedex
,
char
name
[
50
])
{
void
AddPlayerToList
(
Pokedex
*
pokedex
,
char
name
[
50
])
{
PlayerNode
*
pointer
=
pokedex
;
PlayerNode
*
ptr
=
pokedex
;
bool
already_exists
=
false
;
while
(
pointer
->
next
!=
NULL
)
{
if
(
strcmp
(
pointer
->
name
,
name
)
==
0
)
{
already_exists
=
true
;
break
;
}
pointer
=
pointer
->
next
;
}
if
(
already_exists
==
true
)
{
return
;
}
pointer
->
next
=
NewPlayerNode
(
name
);
}
// Searches Player List for name, if the name is not found NULL is returned
PlayerNode
*
FindPlayer
(
Pokedex
*
pokedex
,
char
name
[
50
])
{
PlayerNode
*
pointer
=
pokedex
;
while
(
pointer
!=
NULL
)
{
if
(
strcmp
(
pointer
->
name
,
name
)
==
0
)
{
return
pointer
;
}
pointer
=
pointer
->
next
;
}
return
NULL
;
}
// Adds the Pokemon to a players list and updates the counter
void
AddPokemonToPlayer
(
Pokedex
*
player
,
Pokedex
*
pokemon
,
char
playerName
[
50
],
char
pokemonName
[
20
])
{
PlayerNode
*
playerptr
=
FindPlayer
(
player
,
playerName
);
PokemonNode
*
pokemonptr
=
FindPokemon
(
pokemon
,
pokemonName
);
if
(
playerptr
->
totalPokemon
<
50
)
{
playerptr
->
PokemonArray
[
playerptr
->
totalPokemon
]
=
pokemonptr
;
playerptr
->
totalPokemon
++
;
}
}
// Creates a new pokemon node and returns a pointer to said node
PokemonNode
*
NewPokemonNode
(
char
name
[
50
],
char
type
[
50
],
char
ability
[
50
])
{
PokemonNode
*
newPoke
=
NULL
;
newPoke
=
malloc
(
sizeof
(
PokemonNode
));
if
(
newPoke
!=
NULL
)
{
strcpy
(
newPoke
->
name
,
name
);
strcpy
(
newPoke
->
type
,
type
);
strcpy
(
newPoke
->
ability
,
ability
);
newPoke
->
next
=
NULL
;
}
return
newPoke
;
}
// Checks if Pokemon name already exists, if not a new node is created
void
AddPokemonToList
(
Pokedex
*
pokedex
,
char
name
[
20
],
char
type
[
20
],
char
ability
[
50
])
{
PokemonNode
*
ptr
=
pokedex
;
bool
exists
=
false
;
bool
exists
=
false
;
while
(
ptr
->
next
!=
NULL
)
{
while
(
ptr
->
next
!=
NULL
)
{
if
(
strcmp
(
ptr
->
name
,
name
)
==
0
)
{
if
(
strcmp
(
ptr
->
name
,
name
)
==
0
)
{
...
@@ -179,70 +124,29 @@ void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20],
...
@@ -179,70 +124,29 @@ void AddPokemonToList(Pokedex* pokedex, char name[20], char type[20],
if
(
exists
==
true
)
{
if
(
exists
==
true
)
{
return
;
return
;
}
}
ptr
->
next
=
NewPokemonNode
(
name
,
type
,
ability
);
ptr
->
next
=
NewPlayerNode
(
name
);
}
// Searches Pokemon List for name, if the name is not found NULL is returned
PokemonNode
*
FindPokemon
(
Pokedex
*
pokedex
,
char
name
[
20
])
{
PokemonNode
*
pointer
=
pokedex
;
while
(
pointer
!=
NULL
)
{
if
(
strcmp
(
pointer
->
name
,
name
)
==
0
)
{
return
pointer
;
}
pointer
=
pointer
->
next
;
}
return
NULL
;
}
// Creates a new player node and returns a pointer to said node
PlayerNode
*
NewPlayerNode
(
char
name
[
50
])
{
PlayerNode
*
new_player
=
NULL
;
new_player
=
malloc
(
sizeof
(
PlayerNode
));
if
(
new_player
!=
NULL
)
{
strcpy
(
new_player
->
name
,
name
);
new_player
->
totalPokemon
=
0
;
new_player
->
next
=
NULL
;
}
return
new_player
;
}
// Checks if Player name already exists, if not a new node is created
void
AddPlayerToList
(
Pokedex
*
pokedex
,
char
name
[
50
])
{
PlayerNode
*
pointer
=
pokedex
;
bool
already_exists
=
false
;
while
(
pointer
->
next
!=
NULL
)
{
if
(
strcmp
(
pointer
->
name
,
name
)
==
0
)
{
already_exists
=
true
;
break
;
}
pointer
=
pointer
->
next
;
}
if
(
already_exists
==
true
)
{
return
;
}
pointer
->
next
=
NewPlayerNode
(
name
);
}
}
// Searches Player List for name, if the name is not found NULL is returned
// Searches Player List for name, if the name is not found NULL is returned
PlayerNode
*
FindPlayer
(
Pokedex
*
pokedex
,
char
name
[
50
])
{
PlayerNode
*
FindPlayer
(
Pokedex
*
pokedex
,
char
name
[
50
])
{
PlayerNode
*
pointe
r
=
pokedex
;
PlayerNode
*
pt
r
=
pokedex
;
while
(
p
ointe
r
!=
NULL
)
{
while
(
p
t
r
!=
NULL
)
{
if
(
strcmp
(
p
ointe
r
->
name
,
name
)
==
0
)
{
if
(
strcmp
(
p
t
r
->
name
,
name
)
==
0
)
{
return
p
ointe
r
;
return
p
t
r
;
}
}
p
ointer
=
pointe
r
->
next
;
p
tr
=
pt
r
->
next
;
}
}
return
NULL
;
return
NULL
;
}
}
// Adds the Pokemon to a players list and updates the counter
//ARRAY SECTION
void
AddPokemonToPlayer
(
Pokedex
*
player
,
Pokedex
*
pokemon
,
char
playerName
[
50
],
char
pokemonName
[
20
])
{
// Add pokemon to player array, updates increment
PlayerNode
*
playerptr
=
FindPlayer
(
player
,
playerName
);
void
AddPokemonToPlayer
(
Pokedex
*
player
,
Pokedex
*
poke
,
char
playerName
[
50
],
char
pokemonName
[
20
])
{
PokemonNode
*
pokemonptr
=
FindPokemon
(
pokemon
,
pokemonName
);
PlayerNode
*
playerptr
=
FindPlayer
(
player
,
playerName
);
PokemonNode
*
pokeptr
=
FindPokemon
(
poke
,
pokemonName
);
if
(
playerptr
->
totalPokemon
<
50
)
{
if
(
playerptr
->
totalPokemon
<
50
)
{
playerptr
->
PokemonArray
[
playerptr
->
totalPokemon
]
=
playerptr
->
PokemonArray
[
playerptr
->
totalPokemon
]
=
poke
mon
ptr
;
pokeptr
;
playerptr
->
totalPokemon
++
;
playerptr
->
totalPokemon
++
;
}
}
}
}
main.exe
0 → 100644
View file @
8e533737
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment