Pointer Structure of Pointing Function in C Language

Pointer Structure of Pointing Function in C Language
r‮fe‬er to:lautturi.com
/*
Example struct pointing to function in C language
*/

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

// Define a structure that contains pointers to functions:

typedef struct audio
{
    // A pointer to the function
    void (*play_ptr)();
    void (*stop_ptr)();
} audio;

void play_function()
{
    printf("Play >");
}

void stop_function()
{
    printf("Stop []");
}

int main(int argc, char *argv[]) {

    audio Player = {play_function, stop_function};
    Player.play_ptr();    //  call play function

    Player.stop_ptr();   // call stop function
    return 0;
}
Created Time:2017-08-29 12:44:23  Author:lautturi