how to read operating greater than 9

Asked

Viewed 27 times

-1

How to read an operand composed of 2 or more characters, in the code I created I go through all the string in order to identify each type of operation and number, only that I am traversing this particular vector and treating each position as a character(char) the part. Therefore, when entering with the value 10, it would not be treated as a number but as 2 characters, in this case 1 and 0.

Follows the code: https://onlinegdb.com/ByCh64VHH

What I can do to display this type of operand ?

P.S.: I don’t want to perform any operation, just display it!

  • 1

    First in C the assignment of a string is not done with the = operator but with the strcpy function of <string. h> (e.g.: res = "SUM";). To identify numbers with multiple digits you have to analyze their input and identify and separate the tokens, remembering that a number can be an integer or a real and the notation can be normal or scientific, with each digit read transform the number by adding this digit to the right.

  • 1

    If you do not need the corresponding numeric value just copy each digit to a string and when there are no more digits add the terminator ' 0', taking into account the possible notations used.

1 answer

1


Lucas, as you are treating each position as a character you could use a loop while to analyze all positions, and in each loop cycle you compare character with character.

  • 1

    I did it and it worked, I should have thought of it right away, I need to reinforce logic, because it was a matter of logic and not of syntax.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.