Convert a string to a statement?

This is a discussion on Convert a string to a statement? within the C Programming forums, part of the General Programming Boards category; Is there a way to convert a string to a function call or other valid C statement? Say I have ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Location
    Little Rock, AR
    Posts
    1

    Convert a string to a statement?

    Is there a way to convert a string to a function call or other valid C statement? Say I have a string char *some_func_call. Can I use what is in that string to create a valid C statement and execute it?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,923
    No, but you can map strings to function pointers.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Pointers to functions article below may help

    http://www.cplusplus.com/doc/tutorial/pointers.html

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    What you are asking to do is typically what can easily be done in an interpreted language, like a Perl or Ruby script. In a compiled language, it is difficult to do unless you've specifically planned for it ahead of time.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 03:13 PM
  3. Convert C++ string to int
    By markucd in forum C++ Programming
    Replies: 11
    Last Post: 01-19-2006, 06:49 AM
  4. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  5. convert double to string problem
    By gandalf_bar in forum C++ Programming
    Replies: 6
    Last Post: 03-15-2004, 04:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21