Re: How do I call a function that has name stored in a character
From: Robert Stankowic (pcdoktor_at_netway.at)
Date: 11/29/03
- Next message: Erik Jälevik: "Re: Constness of function return value"
- Previous message: Martijn Lievaart: "Re: Constness of function return value"
- In reply to: Richard Heathfield: "Re: How do I call a function that has name stored in a character"
- Next in thread: Richard Heathfield: "Re: How do I call a function that has name stored in a character"
- Reply: Richard Heathfield: "Re: How do I call a function that has name stored in a character"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 29 Nov 2003 14:42:57 +0100
"Richard Heathfield" <dontmail@address.co.uk.invalid> schrieb im Newsbeitrag
news:bq9u8t$583$1@sparta.btinternet.com...
> Robert Stankowic wrote:
>
> <snip>
>
> > FILE *cmd_file = fopen("c:\\functions.txt", "r");
> >
> > if(cmd_file)
> > {
> > /*read a line from your file and extract the functionname*/
> > while(fgets(line, sizeof line, cmd_file))
>
> What if the line is too long to fit into the buffer?
Well, if the OP uses function names of more than 253 characters, he deserves
what he gets. *g,d&r*
Seriously, I was aware of that, but tried to keep the example as simple as
possible and forgot to mention that.
Thank you for pointing it out.
> > {
> > /*Then find a matching name in the array*/
> > for(function_index = 0; function_index < NUM_FUNCTIONS
> > && !strstr(line, funclist[function_index]);
> > function_index++)
> > {
> > }
>
> Linear search is fine if there aren't many functions. If there are quite a
> few, though, it would be better to make sure that the function list is
> sorted by function name (using the string as the key), and doing a binary
> search.
Of course. Also having a twenty page switch statement would not be nice, so
a binary search plus an array of function pointers will certainly be an
advantage in that case. One small problem with the bsearch() approach is,
that bsearch() returns a pointer and some "fiddling around" will be
necessary to convert that to an index into an array.
[OT]Btw. "to an index into an array" sounds a little bit strange in my
ears - is it correct?[/OT]
kind regards
Robert
- Next message: Erik Jälevik: "Re: Constness of function return value"
- Previous message: Martijn Lievaart: "Re: Constness of function return value"
- In reply to: Richard Heathfield: "Re: How do I call a function that has name stored in a character"
- Next in thread: Richard Heathfield: "Re: How do I call a function that has name stored in a character"
- Reply: Richard Heathfield: "Re: How do I call a function that has name stored in a character"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|