Function name as a parameter to main in C

Viewed 1328

I have a main function as follows:

#include <stdio.h>

int main(int argc, char *argv[])
{
    int i, sum = 0;
    char *func_user = argv[1];

    // execute func_user function

    return 0;
}

void foo1(void)
{
    printf("I'm foo1.");
}

void foo2(void)
{
    printf("I'm foo2.");
}

void foo3(void)
{
    printf("I'm foo3.");
}

I want user to give his function name as an argument to main and I want my program to execute this given function. Is there any way to do this (something like using reflection) without using switch/case like methods?

4 Answers
Related