Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C Function Call Loop

Tags:

c

loops

Lets say i've got functions named Function1,Function2,Function3 etc. Is there a way of calling one of the functions in a loop each time?

for(i=1;i<Max;i++)
{
Function^();
}
like image 511
Makombe Avatar asked Dec 20 '22 01:12

Makombe


1 Answers

Try this:

#include <stdio.h>

void func1(void)
{
    printf( "func1\n" );
}

void func2(void)
{
    printf( "func2\n" );
}

void func3(void)
{
    printf( "func3\n" );
}

typedef void ( *func )(void);

int main(void)
{
    func m_func[3] = {func1, func2, func3};
    int index;

    for( index = 0; index < 3; index++ )
    {
        m_func[index]();
    }

    return 0;
}
like image 186
walruz Avatar answered Jan 04 '23 20:01

walruz