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
bd0d4a69
Commit
bd0d4a69
authored
Jan 17, 2023
by
elijah vasquez
🦍
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finalmaybe
parent
f6c18628
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
266 additions
and
19 deletions
+266
-19
functions.h
functions.h
+16
-14
liststructure.c
liststructure.c
+1
-3
main.c
main.c
+249
-2
No files found.
functions.h
View file @
bd0d4a69
// Structs and functions placed here
// Pokemon List
typedef
struct
PokemonNode
{
char
name
[
10
0
];
char
type
[
10
0
];
char
ability
[
10
0
];
char
name
[
2
0
];
char
type
[
2
0
];
char
ability
[
3
0
];
struct
PokemonNode
*
next
;
}
PokemonNode
;
// Player List
typedef
struct
PlayerNode
{
char
name
[
10
0
];
char
name
[
5
0
];
int
totalPokemon
;
PokemonNode
*
PokemonArray
[
10
0
];
//Array of players
PokemonNode
*
PokemonArray
[
2
0
];
//Array of players
struct
PlayerNode
*
next
;
}
PlayerNode
;
...
...
@@ -26,22 +27,23 @@ typedef struct Pokedex
// Pokemon List functions
PokemonNode
*
NewPokemonNode
(
char
name
[
100
],
char
type
[
100
],
char
ability
[
10
0
]);
void
AddPokemonToList
(
Pokedex
*
funct
,
char
name
[
100
],
char
type
[
100
],
char
ability
[
10
0
]);
PokemonNode
*
FindPokemon
(
Pokedex
*
funct
,
char
name
[
10
0
]);
PokemonNode
*
NewPokemonNode
(
char
name
[
20
],
char
type
[
20
],
char
ability
[
3
0
]);
void
AddPokemonToList
(
Pokedex
*
funct
,
char
name
[
20
],
char
type
[
20
],
char
ability
[
3
0
]);
PokemonNode
*
FindPokemon
(
Pokedex
*
funct
,
char
name
[
2
0
]);
// Player List functions
PlayerNode
*
NewPlayerNode
(
char
name
[
100
]);
// Create new node, return pointer to node
void
AddPlayerToList
(
Pokedex
*
funct
,
char
name
[
100
]);
// Check if name already exists in Player list.
PlayerNode
*
FindPlayer
(
Pokedex
*
funct
,
char
name
[
100
]);
// Searches Player list for name.
void
AddPokemonToPlayer
(
Pokedex
*
funct
,
Pokedex
*
funct2
,
char
playerName
[
100
],
char
pokemonName
[
100
]);
// Adds Pokemon to player's Pokemon list
PlayerNode
*
NewPlayerNode
(
char
name
[
50
]);
// Create new node, return pointer to node
void
AddPlayerToList
(
Pokedex
*
funct
,
char
name
[
50
]);
// Check if name already exists in Player list.
PlayerNode
*
FindPlayer
(
Pokedex
*
funct
,
char
name
[
50
]);
// Searches Player list for name.
void
AddPokemonToPlayer
(
Pokedex
*
funct
,
Pokedex
*
funct2
,
char
playerName
[
50
],
char
pokemonName
[
20
]);
// Adds Pokemon to player's Pokemon list
// Additional functions for the pokedex
// Pokemon details functs
void
DisplayPokemonDetails
(
Pokedex
*
funct
,
char
name
[
100
]);
// Output details of pokemon
void
DisplayPokemonDetails
(
Pokedex
*
funct
,
char
name
[
20
]);
// Output details of pokemon
PokemonNode
*
ListPokemon
(
Pokedex
*
funct
);
//output list of names of all POKEMON in pokedex
// Pokemon players functs
void
DisplayPlayerDetails
(
Pokedex
*
funct
,
char
name
[
100
]);
// output details of players, incl. list of names of pokemon owned
void
DisplayPlayerDetails
(
Pokedex
*
funct
,
char
name
[
50
]);
// output details of players, incl. list of names of pokemon owned
PlayerNode
*
ListPlayers
(
Pokedex
*
funct
);
//output list of names of all PLAYERS in pokedex
functioncall
.c
→
liststructure
.c
View file @
bd0d4a69
// Calling of functions and setting up nodes
#include "functions.h"
int
main
(
void
)
{
// Adding Pokemon to list
...
...
@@ -17,11 +16,10 @@ int main(void)
// Adding pokemon to player
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"armin"
,
"blastoise"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"armin"
,
"dragapult"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"chase"
,
"dragapult"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"chase"
,
"regieleki"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"chase"
,
"volcarona"
);
AddPokemonToPlayer
(
pokeHead
,
playerHead
,
"ziggy"
,
"regieleki"
);
// To display all of both pokemon and players
ListPokemon
(
pokeHead
);
ListPlayers
(
playerHead
);
...
...
main.c
View file @
bd0d4a69
// Main: setting up nodes and printing
#include "functioncall.c"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "liststructure.c"
#include"functions.h"
// Details of Pokemon
void
DisplayPokemonDetails
(
Pokedex
*
pokedex
,
char
name
[
50
])
{
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
);
printf
(
"primary ability: %s
\n
"
,
headPoke
->
ability
);
return
;
}
headPoke
=
headPoke
->
next
;
}
}
// Details of Player
void
DisplayPlayerDetails
(
Pokedex
*
pokedex
,
char
name
[
50
])
{
PlayerNode
*
playerHead
=
FindPlayer
(
pokedex
,
name
);
printf
(
"
\n
PLAYER DETAILS
\n
name: %s
\n
"
,
playerHead
->
name
);
printf
(
"pokemon owned: %d
\n
"
,
playerHead
->
totalPokemon
);
printf
(
"pokemon they have:
\n
"
);
if
(
playerHead
->
totalPokemon
>
0
)
{
for
(
int
i
=
0
;
i
<
playerHead
->
totalPokemon
;
i
++
)
{
printf
(
"%s
\n
"
,
playerHead
->
PokemonArray
[
i
]);
}
}
}
// List ALL Pokemon
PokemonNode
*
ListPokemon
(
Pokedex
*
pokedex
)
{
PokemonNode
*
headPoke
=
pokedex
;
printf
(
"
\n
ALL POKEMON
\n
"
);
while
(
headPoke
!=
NULL
)
{
printf
(
"%s
\n
"
,
headPoke
->
name
);
headPoke
=
headPoke
->
next
;
}
return
headPoke
;
}
// List ALL Players
PlayerNode
*
ListPlayers
(
Pokedex
*
pokedex
)
{
PlayerNode
*
playerHead
=
pokedex
;
printf
(
"
\n
ALL PLAYERS:
\n
"
);
while
(
playerHead
!=
NULL
)
{
printf
(
"%s
\n
"
,
playerHead
->
name
);
playerHead
=
playerHead
->
next
;
}
return
playerHead
;
}
// 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
;
while
(
ptr
->
next
!=
NULL
)
{
if
(
strcmp
(
ptr
->
name
,
name
)
==
0
)
{
exists
=
true
;
break
;
}
ptr
=
ptr
->
next
;
}
if
(
exists
==
true
)
{
return
;
}
ptr
->
next
=
NewPokemonNode
(
name
,
type
,
ability
);
}
// 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
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
;
while
(
ptr
->
next
!=
NULL
)
{
if
(
strcmp
(
ptr
->
name
,
name
)
==
0
)
{
exists
=
true
;
break
;
}
ptr
=
ptr
->
next
;
}
if
(
exists
==
true
)
{
return
;
}
ptr
->
next
=
NewPokemonNode
(
name
,
type
,
ability
);
}
// 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
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
++
;
}
}
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