// Una tabla de funciones: elegir la operación es buscar una fila.
#include <stdio.h>
#include <string.h>

typedef int (*BinaryOp)(int, int);

typedef struct {
    const char *name;
    BinaryOp run;
} Operation;

int add(int a, int b) {
    return a + b;
}

int subtract(int a, int b) {
    return a - b;
}

int multiply(int a, int b) {
    return a * b;
}

int larger(int a, int b) {
    return a > b ? a : b;
}

const Operation *find_operation(const Operation *table, int n, const char *name) {
    for (int i = 0; i < n; i++) {
        if (strcmp(table[i].name, name) == 0) {
            return &table[i];
        }
    }
    return NULL;
}

int main(int argc, char *argv[]) {
    const Operation table[] = {
        {"suma", add},
        {"resta", subtract},
        {"producto", multiply},
        {"mayor", larger},
    };
    int rows = sizeof(table) / sizeof(table[0]);
    int a = 12;
    int b = 5;

    if (argc != 2) {
        printf("uso: %s operación\n", argv[0]);
        return 1;
    }
    const Operation *chosen = find_operation(table, rows, argv[1]);
    if (chosen == NULL) {
        printf("no conozco la operación %s\n", argv[1]);
        return 1;
    }
    printf("%s de %d y %d: %d\n", chosen->name, a, b, chosen->run(a, b));
    return 0;
}
