/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
typedef enum eAnimalType
{
CAT,
DOG
} eAnimalType_t;
typedef struct sDog
{
eAnimalType_t animalType;
char *sound;
int randomInteger;
float randomFloat;
}sDog_t;
typedef struct sCat
{
eAnimalType_t animalType;
char *sound;
int randomInteger;
int anotherRandomInteger;
}sCat_t;
void animal_sound (void *animal)
{
switch (*((eAnimalType_t *)animal))
{
case CAT:
{
sCat_t *catType = (sCat_t *)animal;
printf ("%s\r\n", catType->sound);
break;
}
case DOG:
{
sDog_t *dogType = (sDog_t *)animal;
printf ("%s\r\n", dogType->sound);
break;
}
default:
{
printf("Here");
break;
}
}
}
int main ()
{
sDog_t dog = {.animalType = DOG, .sound = "bark!"};
sCat_t cat = {.animalType = CAT, .sound = "meow!"};
animal_sound (&dog);
return 0;
}