pointer to function with structure
brad at bradley.UUCP
brad at bradley.UUCP
Thu Jan 31 12:41:00 AEST 1985
I found it here it is if you want.
#include <stdio.h>
struct mesg {
char *m_str;
int (*funcp)();
};
int f1();
int f2();
struct mesg mesg[] = {
{"This is message 1", f1 },
{"This is message 2", f2 },
};
main()
{
char gt[5];
while(gets(gt) != NULL) {
switch(gt[0]) {
case '1':
(*mesg[0].funcp)(1);
break;
case '2':
(*mesg[1].funcp)(2);
break;
}
}
}
f1(i)
int i;
{
printf("%s\n", mesg[i-1].m_str);
printf("%d\n",i);
}
f2(i)
int i;
{
printf("%s\n", mesg[i-1].m_str);
printf("%d\n",i);
}
More information about the Comp.lang.c
mailing list