-2

I have a problem with converting this input: 1/2 + 3/4 for example. This input is given as string. How can I convert it into integers and do the addition with this fractions. Here is my code:

int main()
{
    char input[30];
    cin.getline(input, 30);
    char *tok;

    tok = strtok(input, "+ /");

    while (tok != NULL)
    {
        cout << tok << endl;
        tok = strtok(NULL, "+ /");
    }
return 0;
}

I splitted the string and extracted the numbers but they are still a chars, so how can i convert them into ints in that while loop?

Kristian Kamenov
  • 347
  • 1
  • 3
  • 12

1 Answers1

-2

Strings containing numbers can be converted to integers using strtol().

John Zwinck
  • 239,568
  • 38
  • 324
  • 436