How to get and evaluate expressions from a string in C
3 answers
Try it yourself. you can use the stack data structure to evaluate this string here, this is the implementation reference (its in C ++) stack data structure for string computation
+3
source to share
You should try TinyExpr . This is one C source code (no dependencies) that you can add to your project.
Using this solution to solve your problem is simple:
#include <stdio.h>
#include "tinyexpr.h"
int main()
{
double result = te_interp("2*8-5+6", 0);
printf("Result: %f\n", result);
return 0;
}
This will print: Result: 17
+1
source to share