jeudi 15 octobre 2020

C Extract Infix (char array) and cast to int

Given a string/char array e.g :

99+(88-77)*(66/(55-44)+33)

How do I extract the numbers and operators?

I would like to store them into two stacks a and b each containing number and operators only.

I am not sure on the logic, I was thinking of scanning each char in the char array, adding the char (number) into another char, until it meets an operator. Then I go to the char(number) and concatenate the string.

Is there a better way to do this, preferabbly without external libraries?

Aucun commentaire:

Enregistrer un commentaire