Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
table of function calls: need sample code
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Me, post: 2416805"] Regarding to my program (simple command line interface). One way to do this is to get a complete line from stdin, this requires dynamic array allocation (and resizing) unless you want to hardcode the max length of a line. The next step is to take this line and tokenize it into smaller substrings. You're basically doing the same code that the runtime does to convert what you type in at a terminal to run your program into the argv array that gets passed as the 2nd parameter to main. This part is optional, you could just pass in the whole line to the function but then each function has to do its own parameter parsing. There are tradeoffs to both ways but tokenizing it into smaller substrings is probably the way to go. The next step is to take the first substring and map it to a function. The easiest way is to just use a bunch of if statements with strcmp (or stricmp if your platform has it), you don't even need function pointers for this. The other ways (which all involve function pointers) are to keep a sorted table and use binary search, use a sorted linked list and linearly look through it, use a hash table, use a binary tree, etc. Once you map the string to the function, just call it with in the tokenized array. The above takes a bit of code to do in C because I'm assuming you want to learn how to do it yourself instead of using somebody else's functions. I'd highly suggest you get this book [URL]http://cm.bell-labs.com/cm/cs/tpop/[/URL] because it pretty much is perfect for somebody with your experience and it covers everything you need to know to write something like that (and then some). [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
table of function calls: need sample code
Top