Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
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
a-j.towse
Pokedex_Assignment
Commits
ed2565c1
Commit
ed2565c1
authored
Jan 03, 2023
by
a-j.towse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
All commented to date
parent
a8969b0a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
33 deletions
+36
-33
main.c
main.c
+36
-33
No files found.
main.c
View file @
ed2565c1
...
...
@@ -97,31 +97,34 @@ void AddPokemonToList(struct Pokedex pokedex,char name[], char type[], char abil
}
}
//Create Findpokemon function, returns pointer to the node if found, NULL (nil) if not found
struct
PokemonNode
*
FindPokemon
(
struct
Pokedex
pokedex
,
char
name
[])
{
struct
PokemonNode
*
FindPokemon
(
struct
Pokedex
pokedex
,
char
name
[])
{
/*Add comments to these two functions*/
PokemonNode
**
ptrHead
=
pokedex
.
ptrToPokemonHead
;
PokemonNode
*
temp
=
*
ptrHead
;
PokemonNode
**
ptrHead
=
pokedex
.
ptrToPokemonHead
;
//Create pointer to pointer variable from pokedex pointer
PokemonNode
*
temp
=
*
ptrHead
;
//Create temp pointer variable to store current node in list traversal
//Traverse list with temp until NULL
while
(
temp
!=
NULL
)
{
//string comparison of current node name and target name
if
(
strcmp
(
temp
->
name
,
name
)
==
0
)
{
return
temp
;
return
temp
;
//If string comparison is true (0) return address of current node
}
temp
=
temp
->
next
;
temp
=
temp
->
next
;
//temp increments to the next item in the list
}
return
NULL
;
}
//Create ListPokemon function, prints a list of pokemon names, returns void
void
ListPokemon
(
Pokedex
pokedex
)
{
PokemonNode
**
ptrHead
=
pokedex
.
ptrToPokemonHead
;
PokemonNode
*
temp
=
*
ptrHead
;
PokemonNode
**
ptrHead
=
pokedex
.
ptrToPokemonHead
;
//Create pointer to pointer variable from pokedex pointer
PokemonNode
*
temp
=
*
ptrHead
;
//Create temp pointer variable to store current node in list traversal
//Traverse list with temp until NULL
while
(
temp
!=
NULL
)
{
printf
(
"Name: %s
\n
"
,
temp
->
name
);
temp
=
temp
->
next
;
printf
(
"Name: %s
\n
"
,
temp
->
name
);
//Print the name of the node that temp is currently pointing to
temp
=
temp
->
next
;
//temp increments to the next item in the list
}
}
...
...
@@ -134,7 +137,7 @@ int main (void) {
pokedex
.
ptrToPlayerHead
=
&
PlayerHead
;
//Set pointer value head of Player List
pokedex
.
ptrToPokemonHead
=
&
PokemonHead
;
//Set pointer value to head of Pokemon List
//Tests for function implementation
/*Tests for function implementation*/
//NewPokemonNode("Charmander","Fire","FireBallz");
...
...
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