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

int totalLegs = 0;

typedef struct Pet
{
	char* name;
	int legs;
	char* voice;
} Pet;

void addPet(Pet * pet, int * totalLegs)
{
	char string[50];
	
	puts("Input name\n");
	gets(string);
	pet->name = (char *) malloc(strlen(string)+1);
	strcpy(pet->name, string);
	
	puts("How many legs?\n");
	scanf("%d", &pet->legs);
	fflush(stdin);
	
	puts("What does it say?\n");
	gets(string);
	pet->voice = (char*)malloc(strlen(string)+1);
	strcpy(pet->voice, string);
	
	(*totalLegs) += pet->legs;
}
	
int main()
{
	Pet pet1;
	addPet(&pet1, &totalLegs);
	
	Pet pet2;
	addPet(&pet2, &totalLegs);
	
	Pet pet3;
	addPet(&pet3, &totalLegs);
	
	printf("The animals have %d legs", totalLegs);
	
	return 0;
}