intnum=0;//used for setting the value for the trainers pokemon count to zero due to a bug
charspace[10]=" ";//used for adding a space to the users pokemon input
chardec[10];//decission variable
charfcheck[10]="n";//used for adding a value to pokemonHas later in the code
charchex[10]="Y";//used later to check if the user has entered the value of 'check'
charcheck[50];strcpy(check,person->Name);//assigns the value of the nodes value 'Name' to 'check'
charPokemonIsAdded[255];strcpy(PokemonIsAdded,person->PokemonHas);//assigns the value of 'PokemonHas' in the node
charPokemonToBeAdded[255];//for user input
if(person->PokemonCount>100){//this is a fix to a bug in the program when there are no input in pokemoncount it has a really high numerical value
person->PokemonCount=num;//this sets that value to zero
}
if(strcmp(PokemonIsAdded,fcheck)==0){//checks whether there is a match between 'fcheck' and PokemonIsAdded
//if there have been no pokemon added before the default value should be 'n'
//and if it is of the value of n then it assigns 'Pokemon: ' to pokemonHas in the list
strcpy(person->PokemonHas,"Pokemon: ");
strcpy(PokemonIsAdded,person->PokemonHas);
}
if(person==NULL){// if there are no trainers in the list it will state it is empty
printf("%s is NULL\n",comment);
}
elseif(strcmp(check,searchT)==0){//if the users input matches with the list (which it should be) runs code
printf("\nName:%s address:%p nextInLine:%p\n",person->Name,person,person->nextInLineT);//tells user the trainer they have chosen so they can see the details of them
printf("Would you like to add to this Trainer?\n");
printf("Y for yes and N for no: ");
gets(dec);//gets user input for decission
if(strcmp(dec,chex)==0){//if the user input is equal to the value 'Y' runs code bellow
printf("\nWhat is the name of the pokemon you want to add? ");
gets(PokemonToBeAdded);//takes user input for what pokemon they want to add
CheckPokemon(pokemon,PokemonToBeAdded,a);//runs function to check whether pokemon is in its list
if(a->LoopBreak==1){//Loopbreak will have the value of one if the pokemon they want to add exists
printf("\nAdding %s\n",PokemonToBeAdded);//prints the name of the pokemon the user is adding
strcat(PokemonIsAdded,PokemonToBeAdded);//combines what the name of the pokemon the user wants to add to the what they already have
strcat(PokemonIsAdded,space);//adds a space to the end so if the user wants to add another pokemon they wont be all one word
strcpy(person->PokemonHas,PokemonIsAdded);//the value of 'pokemonUsAdded' is copied to the 'PokemonHas' variable in the trainer node
person->PokemonCount++;//increases the trainers pokemon count by one
printf(person->PokemonHas);//prints out all the pokemon the trainer currently has for confirmation
a->LoopBreak--;//sets 'LoopBreak' back to zero so it can be reused
}
else{//if loobreak is not the value of 1 that means the program was unable to find the pokemon the user wanted to add
printf("Pokemon input is not in pokedex\n");//thus it informs the user and goes back to the main loop
}
}
else{//if the user has not inputed a value then it outputs what the user has done and it will go back to the main loop
voidPrintPList(conststructPokemon*list)//functions the same to the trainer equivilent
{
printf("printing List:\n");
conststructPokemon*t;
t=list;
if(t==NULL)
{
printf("List is empty\n");
}
else
{
while(t)
{
printPokemon(t,"t");
t=t->nextInLineP;
}
}
}
voidCleanUp(structsPerson*list,structPokemon*listP){//function for freeing data from memory
structsPerson*next;//creates pointer
structPokemon*nextP;
while(list)//frees all content of the trainer list
{
next=list->nextInLineT;//next as the next node to the current node
printf("Cleaning %s\n",list->Name);
free(list);// frees memory
list=next;//sets the next node as the curent node
}
while(listP)//frees content from pokemon list
{
nextP=listP->nextInLineP;
printf("Cleaning %s\n",list->Name);
free(listP);
listP=next;
}
}
intmain(void)
{
printf("\n\n** START **\n\n");
structsPerson*firstT=NULL;
structsPerson*addedT=NULL;
structPokemon*firstP=NULL;
structPokemon*addedP=NULL;
loopa;
a.LoopBreak=0;
loop*re=&a;
charcommand[64];
charName[50];
charPokemonHas[255];
intPokemonCount=0;
charPName[50];
charType[50];
charability[50];
charsearchT[50];
while(1)//runs the script constantly
{
printf("\n1|Enter 'q' for quit\n");
printf("2|Type 'printT' to print all Trainers\n");
printf("3|Type 'printP' to print all Pokemon\n");
printf("4|Type 'Pokemon' to add a Pokemon\n");
printf("5|Type searchT to search for a Trainer or add a pokemon to them\n");
printf("6|Type 'Trainer' to add a trainer\n");
printf(" |Enter a command: ");
fgets(command,64,stdin);//users command is taken
if(strcmp("q\n",command)==0)//if user enters 'q' the loop will break
{
printf("Quitting...\n");
break;
}
elseif(strcmp("printT\n",command)==0){//user entering 'printT' will run the PrintList function
printf("Printing...\n");
PrintTList(firstT);
}
elseif(strcmp("printP\n",command)==0){//user entering 'printP' will run PrintPList function
printf("Printing...\n");
PrintPList(firstP);
}
elseif(strcmp("searchT\n",command)==0){//user entering 'searchT' will run the SearchTList function
printf("Who would you like to search for/update?");
gets(searchT);//takes user input for what trainer they want the details for/update
printf("Searching...\n");
SearchTList(firstT,firstP,searchT,re);// pointers to the pokemon and trainer lists are passed through, who they want to search for and a pointer to the lookbreaker is passed also
}
elseif(strcmp("Trainer\n",command)==0){//if user enters 'Trainer' then the code bellow runs
printf("Enter Trainer name: ");
gets(Name);// user inputs trainer they want to add
printf("Adding %s\n",Name);
if(firstT==NULL)//if the list is empty
{
firstT=getNewPerson(Name,PokemonHas);//value of the result of the function getNewPerson is assigned to 'firstT'
if(firstT!=NULL)//if it is not empty
{
addedT=firstT;//assigns the value of firstT to addedT
}
}else//otherwise if the list is not empty
{
addedT->nextInLineT=getNewPerson(Name,PokemonHas);//passes the values through the function getNewPerson and what is returned to assigned to the node next in line
if(addedT->nextInLineT!=NULL)//if the next in line for 'addedT' is not empty
{
addedT=addedT->nextInLineT;//assign the next value in line of 'addedT' to addedT
}
}
}
elseif(strcmp("Pokemon\n",command)==0){//functions the same as adding a trainer accept for adding a pokemon
printf("Enter Pokemon name: ");
gets(PName);// user inputs trainer they want to search for