Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: Notesfiles $Revision: 1.6.2.17 $; site bradley.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!ihnp4!inuxc!pur-ee!uiucdcs!bradley!brad From: brad@bradley.UUCP Newsgroups: net.lang.c Subject: pointer to function with structure Message-ID: <9300002@bradley.UUCP> Date: Wed, 30-Jan-85 21:27:00 EST Article-I.D.: bradley.9300002 Posted: Wed Jan 30 21:27:00 1985 Date-Received: Sat, 2-Feb-85 00:22:30 EST Lines: 52 Nf-ID: #N:bradley:9300002:000:955 Nf-From: bradley!brad Jan 30 20:27:00 1985 I can't seem to get the hang of this one. Anyone got anyideas on how to do it. below is the code I thought would work but it doesn't. Basically what I want to do is to be able to insert the function into the structure and have it call that function. Bradley Smith UUCP: {cepu,ihnp4,noao,uiucdcs}!bradley!brad Text Processing ARPA: cepu!bradley!brad@UCLA-LOCUS Bradley University PH: (309) 676-7611 Ext. 446 Peoria, IL 61625 ------------------------cut here------------------------ #include 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)(); break; case '2': mesg[1].(*funcp)(); break; } } } f1() { printf("%s\n", mesg[0].m_str); printf("f1\n"); } f2() { printf("%s\n", mesg[1].m_str); printf("f1\n"); }