I am trying to find a way to convert a string to the lines of my code.
For example, i want to try someting like this:
int x=3;
char str[80];
gets(str); // Assuming the user gives input: "x + 3"
y = str;
printf("%d",y); // Output: "6" (3 + 3)
So that this program outputs “6” (3+3).
I want to this for building a function plotter.. But here I get stuck and can’t find any way. Would you please show me a way to convert these strings to lines of code?
What you want to do is expression evaluation. I suggest 2 methods which perhaps help you to get closer to the expected solution.
Evaluate the expression with a binary tree: build a tree wich represents the expression and the precedence among the operators.
May be it was mentioned above. Polish-form, stack-based evaluation. First build the polish-form of the original expression with a stack, and than evaluate the polish-form with a stack again. And the last: use google with these keywoards 🙂