Is this what you want:
Code:
#include <stdio.h>
#include <string.h>
typedef int (*fnptr) (double, double);
struct abc
{
char check1[30], check2[30], check3[30];
fnptr func1, func2, func3;
} mystruct;
int foo1(double t1, double t2)
{
printf("%f %f\n", t1, t2);
return(1);
};
int foo_default(double t1, double t2)
{
printf("Default function: %f %f\n", t1, t2);
return(1);
};
void myfunc(const char a[], fnptr *ptr)
{
*ptr = foo_default;
if (strcmp(a, "foo") == 0) *ptr = foo1;
}
int main(void)
{
strcpy(mystruct.check1, "foo");
myfunc(mystruct.check1, &mystruct.func1);
mystruct.func1(1.0, 2.0);
strcpy(mystruct.check1, "notfoo");
myfunc(mystruct.check1, &mystruct.func1);
mystruct.func1(1.0, 2.0);
return(0);
}
/*
Output:
1.000000 2.000000
Default function: 1.000000 2.000000
*/