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
a2560e32
Commit
a2560e32
authored
Jan 17, 2023
by
elijah vasquez
🦍
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit9000
parent
e4ce6059
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
15 deletions
+18
-15
liststructure.c
liststructure.c
+2
-1
main.c
main.c
+16
-14
main.exe
main.exe
+0
-0
No files found.
liststructure.c
View file @
a2560e32
...
...
@@ -27,7 +27,8 @@ int main(void)
// Display details of each player
/*
This section can be regarded as a dissection of ListPokemon
and ListPlayers.
and ListPlayers with its assigned function declaration in
main.c.
*/
DisplayPlayerDetails
(
playerHead
,
"armin"
);
DisplayPlayerDetails
(
playerHead
,
"chase"
);
...
...
main.c
View file @
a2560e32
...
...
@@ -3,19 +3,20 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "liststructure.c"
#include "liststructure.c"
// relating main to file containing lists
// Setting up nodes for printing out
// Details of Pokemon
void
DisplayPokemonDetails
(
Pokedex
*
pokedex
,
char
name
[
20
])
{
PokemonNode
*
headPoke
=
pokedex
;
while
(
headPoke
!=
NULL
)
{
if
(
strcmp
(
headPoke
->
name
,
name
)
==
0
)
{
printf
(
"
\n
POKEMON DETAILS
\n
name: %s
\n
"
,
headPoke
->
name
);
printf
(
"type: %s
\n
"
,
headPoke
->
type
);
void
DisplayPokemonDetails
(
Pokedex
*
pokedex
,
char
name
[
20
])
{
// display function at start of main, pokedex struct points to variable pokedex
PokemonNode
*
headPoke
=
pokedex
;
// pokemon points to head of itself to equal the pokedex variable declared in the above function
while
(
headPoke
!=
NULL
)
{
// While pokemon node head does not equal null, will return correct strings
if
(
strcmp
(
headPoke
->
name
,
name
)
==
0
)
{
// checks if name stored in pokemon head is similar to name input variable
printf
(
"
\n
POKEMON DETAILS
\n
name: %s
\n
"
,
headPoke
->
name
);
// to print out pokemon details starting with name
printf
(
"type: %s
\n
"
,
headPoke
->
type
);
//head of pokemon node access store for type and will print out in string
printf
(
"primary ability: %s
\n
"
,
headPoke
->
ability
);
return
;
}
headPoke
=
headPoke
->
next
;
headPoke
=
headPoke
->
next
;
//pokemon node head accessing the "next" pointer to traverse singly linked list
}
}
...
...
@@ -26,7 +27,7 @@ void DisplayPlayerDetails(Pokedex* pokedex, char name[50]) {
printf
(
"pokemon owned: %d
\n
"
,
playerHead
->
totalPokemon
);
printf
(
"pokemon they have:
\n
"
);
if
(
playerHead
->
totalPokemon
>
0
)
{
for
(
int
i
=
0
;
i
<
playerHead
->
totalPokemon
;
i
++
)
{
for
(
int
i
=
0
;
i
<
playerHead
->
totalPokemon
;
i
++
)
{
// Prints list out vertically instead of horizontal rows
printf
(
"%s
\n
"
,
playerHead
->
PokemonArray
[
i
]);
}
}
...
...
@@ -58,7 +59,6 @@ PlayerNode* ListPlayers(Pokedex* pokedex) {
PokemonNode
*
NewPokemonNode
(
char
name
[
20
],
char
type
[
20
],
char
ability
[
30
])
{
PokemonNode
*
newPoke
=
NULL
;
newPoke
=
malloc
(
sizeof
(
PokemonNode
));
if
(
newPoke
!=
NULL
)
{
strcpy
(
newPoke
->
name
,
name
);
strcpy
(
newPoke
->
type
,
type
);
...
...
@@ -97,7 +97,7 @@ PokemonNode* FindPokemon(Pokedex* pokedex, char name[20]) {
return
NULL
;
}
// Creates a new player node and returns a pointer to said node
PlayerNode
*
NewPlayerNode
(
char
name
[
50
])
{
PlayerNode
*
playerNew
=
NULL
;
playerNew
=
malloc
(
sizeof
(
PlayerNode
));
...
...
@@ -110,7 +110,7 @@ PlayerNode* NewPlayerNode(char name[50]) {
return
playerNew
;
}
// Checks if Player name already exists, if not a new node is created
void
AddPlayerToList
(
Pokedex
*
pokedex
,
char
name
[
50
])
{
PlayerNode
*
ptr
=
pokedex
;
bool
exists
=
false
;
...
...
@@ -127,7 +127,7 @@ void AddPlayerToList(Pokedex* pokedex, char name[50]) {
ptr
->
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
*
ptr
=
pokedex
;
while
(
ptr
!=
NULL
)
{
...
...
@@ -150,3 +150,5 @@ void AddPokemonToPlayer(Pokedex* player, Pokedex* poke, char playerName[50], cha
playerptr
->
totalPokemon
++
;
}
}
// DOESN'T PRINT OUT LISTS, RUNNING OUT OF TIME
\ No newline at end of file
main.exe
View file @
a2560e32
No preview for this file type
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