text: #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  
  
  char const* dogGreet(void){ return "vau!"; }
  char const* dogMenu(void){ return "kuhanu govedinu"; }
  char const* catGreet(void){ return "mijau!"; }
  char const* catMenu(void){ return "konzerviranu tunjevinu"; }
  
  typedef char const* (*PTRFUN)();
  // char const* (*dog_fs[2])() = {&dogGreet, &dogMenu};
  // char const* (*cat_fs[2])() = {&catGreet, &catMenu};
  PTRFUN dog_fs[] = {&dogGreet, &dogMenu};
  PTRFUN cat_fs[] = {&catGreet, &catMenu};
   
  
   struct Animal{
    const char* name;
    PTRFUN* functions;
  };
  
  void AnimalPrintGreeting(struct Animal* animal_ptr){
        printf("%s pozdravlja: %s\n", animal_ptr->name, (*(animal_ptr->functions))());
  }
  
  void AnimalPrintMenu(struct Animal* animal_ptr){
        printf("%s voli: %s\n", animal_ptr->name, (*((animal_ptr->functions)+1))());
  }
  
  struct Animal* constructDog( struct Animal* animal_ptr, char* dogName ){
      animal_ptr->name = dogName;
      animal_ptr->functions = dog_fs;
  }
  
  struct Animal* constructCat( struct Animal* animal_ptr, char* catName ){
      animal_ptr->name = catName;
      animal_ptr->functions = cat_fs;
  }
  
  struct Animal* createDog(char* name){
    struct Animal* animal_mem = malloc(sizeof(struct Animal));
    return constructDog(animal_mem, name);
  }
  
  struct Animal* createCat(char* name){
    struct Animal* animal_mem = malloc(sizeof(struct Animal));
    return constructDog(animal_mem, name);
  }
  
  void create_n_dogs(int n){
    struct Animal* dogs = (struct Animal*) malloc(n*sizeof(struct Animal));
  
    for(int i=0; i<n; i++){
      char* buff = malloc(10*sizeof(char));
       sprintf(buff,"%d", i+1);
       constructDog(dogs+i, buff);
    }
    for(int i=0; i<n; i++){
      AnimalPrintGreeting((dogs+i));
    }
  }
  
  void testAnimals(void){
    struct Animal* p1=createDog("Hamlet");
    struct Animal* p2=createCat("Ofelija");
    struct Animal* p3=createDog("Polonije");
  
    AnimalPrintGreeting(p1);
    AnimalPrintGreeting(p2);
    AnimalPrintGreeting(p3);
  
    AnimalPrintMenu(p1);
    AnimalPrintMenu(p2);
    AnimalPrintMenu(p3);
  
    free(p1); free(p2); free(p3);
  }
  
  
  
  int main(){
  
  
      testAnimals();
      create_n_dogs(15);
  
      //na stogu
      struct Animal doggo;
      doggo.name = "mr husky";
      doggo.functions = dog_fs;
  
      AnimalPrintGreeting(&doggo);
  
      //na heapu
      struct Animal* doggo2 = createDog("mr corgi");
      AnimalPrintGreeting(doggo2);
  
  
      
  }