int main()
{
int counter = 0;
int x, y, z;
string command;
char * pch;
string a, b, c, d, e, f;
cout << "Reservations>>";
cin.get (command);
pch = strtok (command," ");
if(command[0] == "n"){
while(pch != NULL)
{
if(counter == 0)
a = pch;
if(counter == 1)
b = pch;
if(counter == 2)
c = pch;
if(counter == 3)
d = pch;
//need to convert char *d to int
pch = strtok (NULL, " ");
counter++;
}
strcat (a,b);
if (strcmp (a, "newflight") !=0)
Flight(c,d);
}
My goal is to take in a command and store it in a string. Different commands have different amounts of information I need. One command is "new flight <flightnumber> <seats available>". First, I try to understand which command is being asked, using the first character to decide. Once I can assume which command is being attempted, I try to separate the string into smaller strings (words) using strtok. I then compare the words that should be constant (new and flight), to make sure the command is syntactically correct (which I use strcmp for). Then I'll go on to create a new flight, which is a class that takes in a char * and integer (which is why I need to convert a char * to integer).
Thanks for any help, feel free to point me in the direction of any guide on why I can't using string commands on these strings..