// This program demonstrates how to access pointers of type struct. // Usually we access with a . , however, when we refer to a pointer // we access with a -> // Sasha Vassar, Week 7 Lecture 11 #include #include #define MAX 15 //1. Define struct struct dog { char name[MAX]; int age; }; int main (void) { //2. Declare struct struct dog jax; //TODO: Demonstrating pointers of type struct //Have a pointer that points to the variable jax of type struct dog struct dog *jax_ptr = &jax; //3. Initialise struct (access members with .) //Remember we can't just do jax.name = "Jax" //So we will use the function strcpy() in to copy the string over //strcpy(jax.name, "Jax"); //jax.age = 6; strcpy(jax_ptr->name, "Jax"); jax_ptr->age = 6; //TODO: Demonstrating pointers of type struct - accessing //How would we initialise it using the pointer? //Perhaps dereference the pointer and access the member? printf("%s is an awesome dog, who is %d years old\n", jax_ptr->name, jax_ptr->age); return 0; }