Commit 35c7169d authored by cosmina.dunca's avatar cosmina.dunca

initial commit

parents
File added
{
"C_Cpp.errorSquiggles": "Disabled"
}
\ No newline at end of file
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
\ No newline at end of file
{
"folders": [
{
"path": "."
}
]
}
\ No newline at end of file
File added
File added
#include <stdio.h>
#include <stdlib.h> // for functions involving memory allocation
#include <string.h> // contains functions for strings and some memory handling functions
#include <stdbool.h> // so that we can use a Boolean variable further in one of the functions
#include "my_functions.h" // adds the file of function definitions and global variable initialisation to the main.c file
int main(void){
Pokedex pokedex; // declaring a variable of Pokedex type to pass to functions insetad of pointers each time
pokedex.headPokemon = NULL; // initialise the head of the Pokemon List to NULL
pokedex.headPlayer = NULL; // initialise the head of the Player List to NULL
pokedex.tailPokemon = NULL; // initialise the tail of the Pokemon List to NULL
FILE *fp; // declaring a pointer of FILE type to open the files containing the data
char line[100];
char *playerN;
char *pokemonName;
char *pokemonType;
char *pokemonAbility; // 4 variables to pass to the functions later
// opening the first file that contains all the players
fp = fopen("playername.txt", "r"); // opening file with reading properties
while (feof(fp) != true){ // while the line exists
fgets(line, 100, fp); // the entire string gets coppied into the variable playerName
if(line[strlen(line) - 1] == '\n') // check to see if the last character of the string is "\n" in which case we eliminate it
line[strlen(line) - 1] = 0;
AddPlayerToList(&pokedex, line); // use this function to add player to the list
}
// opening the second file that contains the pokemons, their types and their abilities
fp = fopen("pokemons.txt", "r"); // the fp variable is reinitialised every time we open a new file (so we don't use 3 FILE variables);
while(feof(fp) != true){
fgets(line, 100, fp);
pokemonName = strtok(line, ","); // here we use the function strtok to delimitate words by "," and store them in the pointers that will later be passed to the function
pokemonType = strtok(NULL, ",");
pokemonAbility = strtok(NULL, ";"); // the last character of each line is ";" so we know when we store the last string (I coulnd't have used space because some abilities have two words)
AddPokemonToList(&pokedex, pokemonName, pokemonType, pokemonAbility);
}
// opening the third file that contains a player's name and the pokemon that will be assigned to that person (same as above)
fp = fopen("pokemonToPlayer.txt", "r");
while (feof(fp) != true)
{
fgets(line, 100, fp);
playerN = strtok(line, ",");
pokemonName = strtok(NULL, ";");
AddPokemonToPlayer(pokedex, playerN, pokemonName); // use funtion to add the pokemons from the file to the corresponding player names in the file
}
// print the head (and tail if the case) of each list:
printf("The head of Pokemon List is: %s.\n", pokedex.headPokemon->name);
printf("The tail of Pokemon List is: %s.\n", pokedex.tailPokemon->name);
printf("The head of Player List is: %s.\n", pokedex.headPlayer->name);
printf("\n");
// test FindPokemon (any other name entered that is not in the list will lead to the error message)
PokemonNode *a = FindPokemon(pokedex, "Articuno"); // create a pointer and assign to it what the function returns (a pointer or NULL)
if(a != NULL)
printf("%s's pointer is: %p\n", a->name, a);
else
printf("There isn't such a pokemon in the list.");
printf("\n");
// test DisplayPokemonsOfSameType (it will dispay the pokemons that have the same type as the string sent to the function)
DisplayPokemonsOfSameType(pokedex, "Fire");
DisplayPokemonsOfSameType(pokedex, "Fairy");
printf("\n");
// test PrintPokemonList && PrintPokemonListBackwards
printf("The list of pokemons is:\n");
PrintPokemonList(pokedex);
printf("\n");
printf("The list of pokemons is:\n");
PrintPokemonListBackwards(pokedex);
printf("\n");
// test FindPlayer (any other name entered that is not in the list will lead to the error message)
PlayerNode *b = FindPlayer(pokedex, "Jude Law"); // create a pointer and assign to it what the function returns (a pointer or NULL)
if(b != NULL)
printf("%s's pointer is: %p\n", b->name, b);
else
printf("There isn't such a player in the list.");
printf("\n");
// test DisplayPlayerDetails
DisplayPlayerDetails(pokedex);
// test PrintPlayerList
printf("The list of players is:\n");
PrintPlayerList(pokedex);
printf("\n");
}
/****************************
Pokemon Functions Declaration
****************************/
PokemonNode *NewPokemonNode(char name[20], char type[20], char ability[40]){
PokemonNode *new_node = NULL; // in case the allocation fails
new_node = malloc(sizeof(PokemonNode)); // gives new_node the address of the first byte of the allocated memory
if (new_node != NULL){ // if the first byte of the allocated memory is not NULL (isnt't empty)
strcpy(new_node->name, name); // it assignes new values to the node created
strcpy(new_node->type, type); // using strcpy function to copy it into the variable
strcpy(new_node->ability, ability);
new_node->next = NULL; // it gives the following node the attribute of NULL so when we add another node we know exactly where the end of the list is
new_node->prev = NULL;
}
return new_node; // returns the address to be given to the previous node
}
void AddPokemonToList(Pokedex *pokedex, char name[20], char type[20], char ability[40]){
PokemonNode *new_node = NewPokemonNode(name, type, ability); // a copy of the address of the node
PokemonNode *temp = pokedex->headPokemon; // copy of the head of the pokemon list
if(pokedex->headPokemon == NULL){ // if it's the first node we add it to the list as the head of the list
new_node->prev = NULL; // the previous element doesn't exist
pokedex->headPokemon = new_node; // the head of the list gets this address
pokedex->tailPokemon = new_node; // so does the tail, in case that's the only element in the list
return;
}
do{
if(strcmp(temp->name, name) == 0) // checks to see if it already exists in the list
return;
if(temp->next == NULL){ // if it's the last one in the list
temp->next = new_node; // will add it to the list
new_node->prev = temp;
pokedex->tailPokemon = new_node; // the next element after the tail is a NULL node
return;
}
temp = temp->next; // if it's not the last one, we move to the next node
} while (temp != NULL);
}
PokemonNode *FindPokemon(Pokedex pokedex, char name[40]){
PokemonNode *temp = pokedex.headPokemon; // makes a copy of the head of the Pokemon List
while (temp != NULL) // iterates through the list with the copy of the head
{
if (strcmp(temp->name, name) == 0) // checks if the name is the one looked for
return temp; // if it is, it's returned
temp = temp->next; // if it isn't, it continues ti iterate
}
return NULL;
}
void DisplayPokemonsOfSameType(Pokedex pokedex, char name[20]){
PokemonNode *temp = pokedex.headPokemon; // copy of the head of the pokemon list
bool ok = false; // a boolean variable to know if there are any pokemons of the type asked for in the list
printf("The %s pokemons are: ", name);
while (temp!=NULL) // iterating
{
if(strcmp(temp->type, name) == 0) // if the type is identical to the parameter name
{
ok = true; // change the boolean variable to exists
printf("%s ", temp->name); // display that pokemon
}
temp = temp->next; // go to the next one
}
if(!ok) // if there aren't any pokemons of that type, print the message
printf("There are no such pokemons in the list.");
printf("\n");
}
void PrintPokemonList(Pokedex pokedex) // same algorithm as before, but it displays all the pokemons from the head
{
PokemonNode *temp = pokedex.headPokemon;
while (temp != NULL)
{
printf("- %s: %s and %s;\n",temp->name, temp->type, temp->ability);
temp = temp->next;
}
}
void PrintPokemonListBackwards(Pokedex pokedex) // same algorithm as before, but it displays all the pokemons from the tail
{
PokemonNode *temp = pokedex.tailPokemon;
while (temp != pokedex.headPokemon)
{
printf("- %s: %s and %s;\n",temp->name, temp->type, temp->ability);
temp = temp->prev;
}
}
/***************************
Player Functions Declaration
***************************/
PlayerNode *NewPlayerNode(char name[40]){
PlayerNode *new_node = NULL; // in case the allocation fails
new_node = malloc(sizeof(PlayerNode)); // gives new_node the address of the first byte of the allocated memory
if (new_node != NULL) // if the first byte of the allocated memory is not NULL (isnt't empty)
{
strcpy(new_node->name, name); // in orderd to give new_node the same name we use strcpy to copy it
new_node->next = NULL; // it gives the following node the attribute of NULL so when we add another node we know exactly where the end of the list is
}
return new_node; // returns the address to be given to the previous node
}
void AddPlayerToList(Pokedex *pokedex, char name[40]){
PlayerNode *new_node = NewPlayerNode(name); // copy of the address
PlayerNode *temp = pokedex->headPlayer; // copy of the head of the player list
if(pokedex->headPlayer == NULL){ // if it's the first node we add it to the list as the head of the list
pokedex->headPlayer = new_node; // give the head its address
return;
}
do{
if(strcmp(temp->name, name) == 0) // checks to see if it already exists in the list
return;
if(temp->next == NULL){ // if it's the last one in the list
temp->next = new_node; // will add it to the list
return;
}
temp = temp->next; // if it's not the last one, we move to the next node
} while (temp != NULL);
}
PlayerNode *FindPlayer(Pokedex pokedex, char name[40]){ // similar to FindPokemon
PlayerNode *temp = pokedex.headPlayer;
while (temp != NULL)
{
if (strcmp(temp->name, name) == 0)
return temp;
temp = temp->next;
}
return NULL;
}
void AddPokemonToPlayer(Pokedex pokedex, char playerName[40], char pokemonName[40]){
PlayerNode *temp = pokedex.headPlayer; // copy of the head of the player list
PokemonNode *tempPo = pokedex.headPokemon; // copy of the head of pokemon list
bool exists = false; // to make sure we can add the pokemon to the player list
while (temp != NULL) // iterate through the player list
{
if (strcmp(temp->name, playerName) == 0) // if the player exists in the list of players
{
for (int i = 1; i <= temp->totalOfPokemons; i++) // for statement for player's array of pokemons
if(strcmp(temp->pokemonArray[i].name, pokemonName) == 0) // if it already exists in the array, we exist the function
return;
while (tempPo) // iterate through the pokemon list
{
if(strcmp(tempPo->name, pokemonName) == 0) // if player exists and the pokemon we want to add is not in his list of pokemons, we check to see if the pokemon exists in the linked list
{
exists = true; // everything's ok so the boolean changes to true
break; // we exist the loop as we don't have to look for it anymore
}
tempPo = tempPo->next; // get to the next pokemon
}
if(exists){ // it everything is fine
temp->totalOfPokemons++; // first we increase the total of pokemons each player has by 1 (we'll iterate each for from 1)
temp->pokemonArray[temp->totalOfPokemons] = *tempPo; // add the pointer to the array
}
}
temp = temp->next; // get to the next player
}
}
void DisplayPlayerDetails(Pokedex pokedex){
PlayerNode *temp = pokedex.headPlayer; // create a copy of the head of the player list and use it to traverse the list
printf("This is a list of all the players and their Pokemons.\n");
while(temp != NULL){ // iterate
printf("Player name: %s\n", temp->name); // display player's name
if(temp->totalOfPokemons == 0) // if the player doesn't own any pokemons
printf("%s doesn't have any pokemons.\n", temp->name);
else if (temp->totalOfPokemons == 1) // if the player only has one pokemon
printf("%s has 1 pokemon.\n", temp->name);
else
printf("%s has %i pokemons.\n", temp->name, temp->totalOfPokemons); // if it has more than one we use a for loop to iterate through the PokemonNode array to display the relevan details
for(int i = 1; i <= temp->totalOfPokemons; ++i)
printf("%i. %s: type - %s, ability - %s\n", i, temp->pokemonArray[i].name, temp->pokemonArray[i].type, temp->pokemonArray[i].ability);
temp = temp->next;
printf("\n");
}
}
void PrintPlayerList(Pokedex pokedex) // same as PrintPokemonList()
{
PlayerNode *temp = pokedex.headPlayer;
while (temp != NULL)
{
printf("- %s\n", temp->name);
temp = temp->next;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.main</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
//my_functions.h
typedef struct PokemonNode // struct for a doubly linked list (Pokemons List)
{
char name[20]; // the name of the Pokemon
char type[20]; // the type of Pokemon
char ability[40]; // Pokemon's ability
struct PokemonNode *next; // pointer to the next Pokemon it is linked to
struct PokemonNode *prev; // pointer to the previous Pokemon it is linked to
}PokemonNode;
typedef struct PlayerNode // struct for a singly linked list (Players List)
{
char name[40]; // the name of the player
int totalOfPokemons; // the number of the pokemons it has collected so far
PokemonNode pokemonArray[21]; // an array of pointers for the pokemons owned by each player (allocate 21 instead of because we start indexing from 1 an the last element in NULL)
struct PlayerNode *next; // pointer to the next player in the linked list
}PlayerNode;
typedef struct Pokedex
{
PokemonNode *headPokemon; // head of the Pokemon List
PokemonNode *tailPokemon; // last element of Pokemon List
PlayerNode *headPlayer; // head of the Player List
}Pokedex;
PokemonNode *NewPokemonNode(char name[20], char type[20], char ability[40]); // creates a new pokemon node
void AddPokemonToList(Pokedex *pokedex, char[20], char type[20], char ability[40]); // once the node is created, this function will link it to the list of pokemons
PokemonNode *FindPokemon(Pokedex pokedex, char name[40]); // searches the list of pokemons to see if there is one that has the name transmitted using the parameter
void DisplayPokemonsOfSameType(Pokedex pokedex, char name[2]); // displays the pokemons of the same type (if the type entered is correct and there are pokemons in the list of that type)
void PrintPokemonList(Pokedex pokedex); // this function will display the pokemons and their chracteristic in order, starting from the head
void PrintPokemonListBackwards(Pokedex pokedex); // because I used a doubly linked, we can also go backwards and this function starts from the tail of the Pokemon List and goes all the way to the head
PlayerNode *NewPlayerNode(char name[40]); // creates a new player node
void AddPlayerToList(Pokedex *pokedex, char name[40]); // once the node is created, this function will link it to the list of players
PlayerNode *FindPlayer(Pokedex pokedex, char name[40]); // searches the list of players to see if there is one that has the name transmitted using the parameter
void AddPokemonToPlayer(Pokedex pokedex, char playerName[40], char pokemonName[40]); // this function has two string parameters, the name of the player and the name of the pokemon that needs to be added to the person's list of pokemons and it does that
void DisplayPlayerDetails(Pokedex pokedex); // this function displays every player and it's list of pokemons and their characteristics
void PrintPlayerList(Pokedex pokedex); // displays the list of players starting from the head
\ No newline at end of file
Natalie Portman
Natalie Portman
Natalie Portman
Brad Pitt
Rachel McAdams
Matthew McConaughhey
Matthew McConaughhey
Anne Hathaway
Leonardo diCaprio
Matthew McConaughhey
Emma Stone
Bradley Cooper
Keira Knightley
Cillian Murphy
Scarlett Johansson
Johnny Depp
Jessica Chastain
Ryan Gosling
Julia Roberts
Jude Law
Margot Robbie
Benedict Cumberbatch
Emma Watson
Henry Cavill
Tom Hiddleston
Tom Holland
Cameron Diaz
Angelina Jolie
Robert Pattinson
Jesse Eisenberg
Julia Roberts
Julia Roberts
Julia Roberts
\ No newline at end of file
Natalie Portman,Ponyta;
Natalie Portman,Ponyta;
Natalie Portman,Gyarados;
Benedict Cumberbatch,Onix;
Benedict Cumberbatch,Jynx;
Emma Stone,Ninetales;
Anne Hathaway,Blastoise;
Cillian Murphy,Larvitar;
Tom Hiddleston,Walrein;
Tom Hiddleston,Dewgong;
Leonardo diCaprio,Onix;
Leonardo diCaprio,Beedrill;
Leonardo diCaprio,Shellder;
Tom Hiddleston,Kakuna;
Tom Hiddleston,Dewgong;
Leonardo diCaprio,Golem;
Leonardo diCaprio,Articuno;
Jesse Eisenberg,Buterfree;
Jesse Eisenberg,Abra;
Jesse Eisenberg,Gyarados;
Jesse Eisenberg,Kadabra;
Cillian Murphy,Rapidash;
Cillian Murphy,Beedrill;
Benedict Cumberbatch,Kadabra;
Benedict Cumberbatch,Kakuna;
Benedict Cumberbatch,Ninetales;
Benedict Cumberbatch,Onix;
Benedict Cumberbatch,Starmie;
Johnny Depp,Walrein;
Brad Pitt,Ponyta;
Brad Pitt,Larvitar;
Brad Pitt,Jynx;
Brad Pitt,Golem;
Henry Cavill,Abra;
Henry Cavill,Kadabra;
Tom Holland,Shellder;
Tom Holland,Starmie;
Robert Pattinson,Kirlia;
Angelina Jolie,Dewgong;
Angelina Jolie,Gyarados;
Robert Pattinson,Onix;
Ryan Gosling,Larvitar;
Rachel McAdams,Articuno;
Cameron Diaz,Ninetales;
Cameron Diaz,Buterfree;
Henry Cavill,Kadabra;
Emma Watson,Golem;
Emma Watson,Blastoise;
Robert Pattinson,Kadabra;
Cameron Diaz,Abra;
Cameron Diaz,Shellder;
Cameron Diaz,Golem;
Cameron Diaz,Gyarados;
Cameron Depp,Kirlia;
Cameron Diaz,Dewgong;
Tom Holland,Dewgong;
Tom Holland,Larvitar;
Tom Holland,Articuno;
Emma Watson,Walrein;
Emma Watson,Ninetales;
Benedict Cumberbatch,Buterfree;
Benedict Cumberbatch,Rapidash;
Margot Robbie,Ninetales;
Jude Law,Walrein;
Jude Law,Larvitar;
Jude Law,Articuno;
Jude Law,Gyarados;
Jude Law,Kakuna;
Julia Roberts,Golem;
Julia Roberts,Kirlia;
Johnny Depp,Abra;
Johnny Depp,Kadabra;
Johnny Depp,Articuno;
Johnny Depp,Onix;
Scarlett Johansson,Dewgong;
Scarlett Johansson,Larvitar;
Scarlett Johansson,Blastoise;
Cillian Murphy,Ninetales;
Cillian Murphy,Dewgong;
Cillian Murphy,Buterfree;
Cillian Murphy,Articuno;
Cillian Murphy,Kadabra;
Cillian Murphy,Abra;
Cillian Murphy,Gyarados;
Cillian Murphy,Kakuna;
Cillian Murphy,Golem;
Cillian Murphy,Onix;
Bradley Cooper,Beedrill;
Bradley Cooper,Ponyta;
Leonardo diCaprio,Ponyta;
Leonardo diCaprio,Abra;
Leonardo diCaprio,Kadabra;
Leonardo diCaprio,Kakuna;
Leonardo diCaprio,Rapidash;
Leonardo diCaprio,Blastoise;
Leonardo diCaprio,Ninetales;
Leonardo diCaprio,Buterfree;
Leonardo diCaprio,Starmie;
Leonardo diCaprio,Jynx;
Leonardo diCaprio,Dewgong;
Leonardo diCaprio,Gyarados;
Leonardo diCaprio,Larvitar;
Leonardo diCaprio,Kirlia;
Leonardo diCaprio,Walrein;
Anne Hathaway,Jynx;
Anne Hathaway,Rapidash;
Matthew McConaughhey,Jynx;
Matthew McConaughhey,Articuno;
Matthew McConaughhey,Blastoise;
Matthew McConaughhey,Starmie;
Rachel McAdams,Gyarados;
\ No newline at end of file
Onix,Rock,Sturdy;
Onix,Rock,Sturdy;
Onix,Rock,Sturdy;
Onix,Rock,Sturdy;
Beedrill,Bug,Swarm;
Buterfree,Bug,Compound Eyes;
Abra,Psychic,Synchronise;
Ponyta,Fire,Run Away;
Rapidash,Fire,Flash Fire;
Blastoise,Water,Torrent;
Kakuna,Bug,Shed Skin;
Ninetales,Fire,Flash Fire;
Ponyta,Fire,Run Away;
Ponyta,Fire,Run Away;
Kadabra,Psychic,Inner Focus;
Shellder,Water,Shell Armor;
Starmie,Psychic,Illuminate;
Jynx,Psychic,Oblivious;
Golem,Rock,Sturdy;
Articuno,Ice,Pressure;
Dewgong,Ice,Hydration;
Gyarados,Water,Intimidate;
Gyarados,Water,Intimidate;
Larvitar,Rock,Guts;
Kirlia,Psychic,Trace;
Gyarados,Water,Intimidate;
Walrein,Ice,Thick Fat;
Gyarados,Water,Intimidate;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment