Saturday, May 22, 2010

How can CONVERSION STRING to FUNCTION in C?for example "f(x)=sin(x=3)+x?

you can't just do it.





compare the string to "sin" and then call the sin function





if(myString == "sin")


{


sin(x);


}





you're going to have to do the processing there though. I'd say consume characters to the first open-parenthesis, and then compare it, then consume what's inside the parenthesis.

How can CONVERSION STRING to FUNCTION in C?for example "f(x)=sin(x=3)+x?
The link below will get you close although it is in C#. Can't remember if C has an Eval function but the gyst is to take any string and break it down into its parts character by character. You will have to extract the variables (x in your case) and you will need to ask the caller what is the value for x. Not sure this is what you are looking for.





The other thought is to offer a function f that takes a value (x) and returns sin(x) and if no value is passed, the I guess you default x to be 3.
Reply:From the little information you gave, I can guess that you want the user to input some function as a string, and then make that as a function within the program dynamically. Well it is possible, but it is a very lengthy process, and certainly not something I would be doing now.


No comments:

Post a Comment