Hi,
The following is an excerpt from a simple unit converter program I am writing. It compiles with no errors, but the code within the if statement under // Convert units, is not run. I have checked that argv[ARG_CONV_FROM] and argv[ARG_CONV_TO] actually do contain the correct data. I assume there must be some incompatibillity issue between the data contained in argv and the "celcius" and "fahrenheit" strings, but I cannot find the error. Please help
Code:
...
int main(int argc, char *argv[]) {
// Variables and constants;
double result = 0;
const int REQUIRED_ARGS = 4;
const int ARG_VALUE = 1;
const int ARG_CONV_FROM = 2;
const int ARG_CONV_TO = 3;
// Check user input
if (argc != REQUIRED_ARGS) {
show_usage();
exit(1);
}
// Convert units
if ((argv[ARG_CONV_FROM] == "celcius") && (argv[ARG_CONV_TO] == "fahrenheit")) {
result = atoi(argv[ARG_VALUE]) * (9 / 5) + 32;
}
printf("Result = %f\n", result);
return 0;
}
...
Using GCC 4.6.0 on Linux Fedora 15