Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Pokedex
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
steven.mappin
Pokedex
Commits
8089bc5e
Commit
8089bc5e
authored
Jan 16, 2023
by
steven.mappin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
ced6807a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
0 deletions
+118
-0
Project.c
Project.c
+118
-0
No files found.
Project.c
0 → 100644
View file @
8089bc5e
#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
\n
Number of Pokemon: %d
\n
List 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
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