Question: I'm having trouble reading input from a file and converting it to a string. The input is supposed to be: 6 3 and I want

I'm having trouble reading input from a file and converting it to a string. The input is supposed to be:

6 3

and I want to save 6 and 3 in separate integer variables. This is the code I have.

char *com, *dummy, *valstr, *op;

while (getline(input2,hold)) {

com = strdup(hold.c_str());

op = strtok(com, " \t");

valstr = strtok(NULL, " \t");

if(valstr != NULL)

l = strtol(valstr, &dummy, 10);

l--;

cout << l << endl;

com = strdup(hold.c_str());

op = strtok(com, " \t");

valstr = strtok(NULL, " \t");

if(valstr != NULL)

f = strtol(valstr, &dummy, 10);

cout << f << endl;

if (words[l].head==NULL || l>SIZE) {

output <<"- ";

break;

}

output << words[l].search(f) << endl;

if (words[l].search(f)=="-" || words[l].head==NULL) {

output <<"- ";

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!