Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
My 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
angel.rivera
My pokedex
Commits
d34bd1e5
Commit
d34bd1e5
authored
Jan 17, 2023
by
Michelangelo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add README
parent
2627da2d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
0 deletions
+89
-0
pokedex.c
pokedex.c
+89
-0
No files found.
pokedex.c
0 → 100644
View file @
d34bd1e5
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Define a struct to store information about a Pokemon
struct
PokemonNode
{
char
name
[
20
];
char
ability
[
20
];
struct
PokemonNode
*
next
;
struct
PokemonNode
*
prev
;
};
// Define a struct to store information about a player
struct
PlayerNode
{
char
name
[
20
];
int
pokemonCount
;
struct
PokemonNode
*
ownedPokemon
[
100
];
struct
PlayerNode
*
next
;
struct
PlayerNode
*
prev
;
};
// Define a struct to store the Pokedex
struct
Pokedex
{
struct
PokemonNode
*
headPokemon
;
struct
PlayerNode
*
headPlayer
;
};
// Create a Pokedex
struct
Pokedex
pokedex
;
// Function to create a new Pokemon node
struct
PokemonNode
*
createPokemonNode
(
char
name
[],
char
ability
[])
{
struct
PokemonNode
*
newNode
=
(
struct
PokemonNode
*
)
malloc
(
sizeof
(
struct
PokemonNode
));
strcpy
(
newNode
->
name
,
name
);
strcpy
(
newNode
->
ability
,
ability
);
newNode
->
next
=
NULL
;
newNode
->
prev
=
NULL
;
return
newNode
;
}
// Function to add a new Pokemon to the list
void
addPokemonToList
(
struct
PokemonNode
*
newNode
)
{
if
(
pokedex
.
headPokemon
==
NULL
)
{
pokedex
.
headPokemon
=
newNode
;
}
else
{
struct
PokemonNode
*
current
=
pokedex
.
headPokemon
;
while
(
current
->
next
!=
NULL
)
{
current
=
current
->
next
;
}
current
->
next
=
newNode
;
newNode
->
prev
=
current
;
}
}
// Function to search for a Pokemon by name
struct
PokemonNode
*
searchPokemonByName
(
char
name
[])
{
struct
PokemonNode
*
current
=
pokedex
.
headPokemon
;
while
(
current
!=
NULL
)
{
if
(
strcmp
(
current
->
name
,
name
)
==
0
)
{
return
current
;
}
current
=
current
->
next
;
}
return
NULL
;
}
// Function to create a new Player node
struct
PlayerNode
*
createPlayerNode
(
char
name
[])
{
struct
PlayerNode
*
newNode
=
(
struct
PlayerNode
*
)
malloc
(
sizeof
(
struct
PlayerNode
));
strcpy
(
newNode
->
name
,
name
);
newNode
->
pokemonCount
=
0
;
newNode
->
next
=
NULL
;
newNode
->
prev
=
NULL
;
return
newNode
;
}
// Function to add a new Player to the list
void
addPlayerToList
(
struct
PlayerNode
*
newNode
)
{
if
(
pokedex
.
headPlayer
==
NULL
)
{
pokedex
.
headPlayer
=
newNode
;
}
else
{
struct
PlayerNode
*
current
=
pokedex
.
headPlayer
;
while
(
current
->
next
!=
NULL
)
{
current
=
current
->
next
;
}
current
->
next
=
newNode
;
newNode
->
prev
=
current
;
}
}
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