Path: utzoo!attcan!uunet!lll-winken!sun-barr!cs.utexas.edu!hellgate.utah.edu!uplherc!giga!unislc!ttobler From: ttobler@unislc.uucp (Trent Tobler) Newsgroups: comp.lang.c Subject: Re: strings & function addresses Message-ID: <1990Oct26.211532.27626@unislc.uucp> Date: 26 Oct 90 21:15:32 GMT References: <3785@wb3ffv.ampr.org> Organization: Unisys, SLC Utah Lines: 58 From article <3785@wb3ffv.ampr.org>, by wmark@wb3ffv.ampr.org (Mark Winsor): > > I need to write a C front end for a cobol application. The cobol programs > will return a string that is the name of the next program to call which is > representing a C function. I need a way to associate that string with the > function address, anybody have any ideas? Please don't suggest I rewrite the > application in C, time doesn't allow that option. > I'm not sure I understand the question, but as I understand it, you require a 'C' function to be associated with a string? If you can get that to a 'C' string, you can use either an array or linked list of structures with a string and a function pointer. Here is an examples, using arrays... /*------------------------*/ f1() { ... } f2() { ... } f3() { ... } struct func_s { char *name; int (*code)(); } myfuncs[] = { { "function1", f1}, { "function2", f2}, { "function3", f3} }; /* then to find a call a function by string ... */ find( string) char *string; { int i; for( i = 0; i < sizeof( myfuncs) / (sizeof( *myfuncd); i++) if( !strcmp( myfuncs[i].name, string) return (myfuncs[i].code)(); /* string was not in list, print an error */ return 0; } ------------------------------------------------------- ___ ___ Trent Tobler ttobler@csulx.weber.edu Internet