Select Git revision
loesung-3-20160129-3.c
Forked from
Peter Gerwinski / hp
326 commits behind the upstream repository.
Peter Gerwinski authored
loesung-3-20160129-3.c 680 B
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char symbol;
int (*calculate) (int a, int b);
}
operation;
operation *new_operation (void)
{
operation *op = malloc (sizeof (operation));
op->symbol = '?';
op->calculate = NULL;
return op;
}
operation *new_plus (void)
{
return new_operation ();
}
operation *new_minus (void)
{
return new_operation ();
}
operation *new_times (void)
{
return new_operation ();
}
int main (void)
{
operation *op[4];
op[0] = new_plus ();
op[1] = new_minus ();
op[2] = new_times ();
op[3] = NULL;
for (int i = 0; op[i]; i++)
printf ("2 %c 3 = %d\n", op[i]->symbol, op[i]->calculate (2, 3));
return 0;
}