Thread: Changing a input string to a function call?

  1. #1
    Registered User
    Join Date
    May 2003

    Changing a input string to a function call?

    Is it possible to change a input string for example sin(pi*x), whereby in the code i have the variables pi and x, such that i can call the sine function as given by the input string. Without having to do string comparison and if statments, as for any general equation composed of sines and exponets and powers this would be really cumbersome

  2. #2
    Registered User
    Join Date
    Jul 2002
    so you want to take a string and stick in the vars data and not its name.

    look into sprintf

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    you mean, you have in a string "sin(pi*x)" and you want to call it directly by the string? I don't think it's possible. But, if you have pi and x defined in your code, just call it, but not from a string

    If I understand you correct, checkout also the sprintf function.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    The answer you want: Yes.
    #include <magic.h>
    int main( void )
        struct MagicItem magicWand;
        wave( magicWand );
        return 0;
    Reality: No.

    You have to set up a parser of some kind for your input, so it knows what the hell you're trying to do. You cannot simply read a string from the keyboard, and without using any checking at all, have it call a function and create variables to display output.

    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Jun 2003
    It's all their fault!! Those stupid guys who have created the C language haven't considerned to make the language understand a string when it is the same as a function and call the function!!
    ( Trying to be a good C Programmer )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM