Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!julius.cs.uiuc.edu!apple!uokmax!occrsh!abcom!mdb From: mdb@abcom.ATT.COM (5013 ) Newsgroups: comp.lang.c Subject: Functions within structures Keywords: structures Message-ID: <2203@abcom.ATT.COM> Date: 6 Nov 90 23:25:29 GMT Organization: AT&T(IMS-DPO), Aurora, Colorado Lines: 81 Hi, netlanders, I need help. I am building a menu using structures and would like to be able to include the function to be run within the structure. Below is an example of what I would like to do. =========================================================================== /**************************************************************************** ** ** Program : CH10.c ** Author : Michael D. Barnes ** Date Created: November 04, 1990 ** Date Revised: ** Notes : This database manager will: ** ** ADD RECORD ** FIND RECORD ** QUIT ** ** Globals used: MENU_ITEM -> Number of items in menu ** MAX_RECS -> Maximum Records in database allowed ** sorted -> Does database need to be sorted? ** phone_bk -> structure phone book data record ** menu -> structure menu data record ** ****************************************************************************/ #include #include #include #include #define MENU_ITEM 2 #define MAX_RECS 6 int add_rec(); int find_rec(); int quit(); unsigned int records=0; typedef struct { char key; int x_row; int y_row; char msg[20]; } MENU; MENU menu[MENU_ITEM+1] = { { '1',7,25,"Add Phone Number",add_rec() }, { '2',9,25,"Find Phone number",find_rec() }, { 'Q',12,25,"QUIT",quit() } } ; int menu_cnt=MENU_ITEM; /* What menu option is used */ main(void) { int menu_opt; disp_menu(menu,menu_cnt); while ( 1 ) { menu_opt = select(); (*(menu[menu_opt].foo))(); gotoxy ( menu[menu_cnt].y_row,menu[menu_cnt].x_row ); printf ( "%c. %s",menu[menu_cnt].key,menu[menu_cnt].msg ); gotoxy ( menu[menu_cnt].y_row,menu[menu_cnt].x_row ); } } ======================================================================= Now, how do I assigned these functions to the structure (or is it posible) and then access these same functions? Any help will be greatly appreciated. Thank for yor help in advance Mike Barnes (415) 224-3030