# extracting function out of a string

This is a discussion on extracting function out of a string within the C Programming forums, part of the General Programming Boards category; hello all i write atm a little programm for my math course. something to determinate the min of a graph. ...

1. ## extracting function out of a string

hello all

i write atm a little programm for my math course.
something to determinate the min of a graph.
i use arguments.

the programm expecting a fuction, something like y= a*x^2+b*x +c (simple example).
instead of x^2 i would use x*x ofc)

now i have this function in a string, how can i calculate this math function ?
or how do i extract it out of the string ?

must it be a huge parser (nearly impossible, as a graph can contain many more arugments like sin/cos etc).

is there something like a eval() function in c ??

thx for help
greetz
Hellshine

2. No, there is no standard function to do this for you. There have doubtless been others working on the same sort of problem, so I bet if you were to do a forum search, or even a Google search, you'd find some pointers.

Quzah.

3. i have tried both, but with some keywords of the problem description i don't find anything helpful here nor in google.
prolly with the right keywords, but i don't even know in what way a solution for this problem could look like.

what i found out that there is no eval fuction for c
and prolly never will be as that is a problem with all compiled languages.

4. Try doing a search using the words "mathematical", "expression", "parser" and "c" or something along those lines. You should get plenty of hits and possibly even some source code to look at.

I had to do a project in college that required we write an expression parser. We had to take an expression and build a tree out of that, then we had to use that tree to differentiate that expression and display it. My skills at programming at that stage in my life were minimal and I still managed to crank something out all by myself that worked.[/edit]