#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
 * Terry Harvey CIS 105 Section 010 TA Tina Weymouth
 *  Demonstration program for struct pointers
 **/

typedef struct{
    int legs;
    char name[20];
} Pet; 

void printPetPtr(Pet *ptr);
void printPet(Pet p);

int main(){

    Pet * p1;       //pointer to type Pet
    Pet * zoo[100]; //one hundred pointers to Pet, but NO PETS
    
    p1 = (Pet *) malloc(sizeof(Pet)); //makes new Pet on heap

    p1->legs = 4;
    (*p1).legs = 3;

    printPet(*p1); //this function takes a real Pet
    printPetPtr(p1); //this function takes a Pet pointer
    
    free(p1); //releases memory on heap

    return 0;

}

Pet makeOnePetOnStack(){

    Pet p = {6, "Bugsy"};
    return p;
}

void printPet(Pet p){
    printf("my pet has %d legs\n", p.legs);
}
void printPetPtr(Pet *ptr){
    printf("my pet has %d legs\n", ptr->legs);
}
