I am trying to figure out how to edit my code to store 2 integers in separate int
variables using strtol()
. So far the code I've been given is:
while (getline(input, command))
{
com = strdup(command.c_str());
op = strtok(com, " \t");
valstr = strtok(NULL, " \t");
if (valstr != NULL) {
val = strtol(valstr, &dummy, 10);
}
if (strcmp(op,"i") == 0) // insert into list
{
cout << "Insert " + to_string(val) << endl;
myBST.insert(val);
}
I understand that op = strtok(com, " \t")
takes the first token of the string as the operator, such as i
to insert, and stores it into the char op
.
I am only confused on the val = strtol(valstr, &dummy, 10);
and valstr = strtok(NULL, " \t");
code. How would I use strtol()
to store a second integer into val2
?
Say, for example, I have the command i 10 20
. From what I understand, i
would be stored into op
and 10
would be stored into val
. How would I store the second integer 20
into a new variable, say val2
?