For school, I'm currently learning C. Coming from Javascript, I'm trying to adapt to the way C is written. The syntax can be a bit confusing. I checked and there are a lot of obsolete functions my teacher used for examples.
My question is based on expression matching.
So let's assume I have a math question like this:
If Hanna has 100 apples and John 32 apples, then what is the sum?
How would I tell the program to interpret the sentence as 1+2
and then output the result?
In javascript, I usually use regular expressions but in C, this is really hard to accomplish or understand since regex is not a standard feature.
First: printf(A operation B)
I would need to iterate over each letter of the string and check if any of the letters include 0-9
. If match is found then the first number is stored in variable A and the second number in Variable B. If sum is found, then it stores + in the operation variable. As a consequence the variables within printf
become assigned and I get the result.
Now how do I do this technically in C?