Hi guys I'm working on a small portion of a larger program here that will accept lines of text and based on the first word in each line needs to conditionally branch...I am using the tolower() function to make the words lowercase and then I test them in an if statement...The problem is that it's not branching on any of the conditional statements...for example I ran the file with the following line of text:
"ThRoW garbage 45 56"
It should have output "throw" to the screen but it did not...at the very end when I output the formatted line of code, it outputs correctly:
"throw 45 56"
I ran the program through gdb and when I got to line 24 I did an info locals to check the values of the variables. It showed:
order = 0x22cbb0 "throw"
I stepped and it went straight to line 26...
I don't understand why the if statement isn't catching it...Any help you could give me would be greatly appreciated...Thanks!
#include <cstdlib>
#include <iostream>
#include <cctype>
using namespace std;
int main(){
char command[256];
char *order=0;
char *token=0;
//char c;
int i=0;
int xcoord, ycoord;
cout << "Enter the command: ";
while(cin.getline(command, 256)){
token = strtok(command," ");
order = token;
while(order[i]){
//c=order[i];
//order[i] = static_cast<char>(tolower(c));
order[i] = tolower(order[i]);
i++;
}
if(order == "add")
cout << order << endl;
if(order == "throw")
cout << order << endl;
if(order == "remove")
cout << order << endl;
token = strtok(NULL," ");
token = strtok(NULL," ");
xcoord = atoi(token);
token = strtok(NULL," ");
ycoord = atoi(token);
cout << order << " " << xcoord << " " << ycoord << endl;
i=0;
}
return 0;
}