BW> cout << "The value of /a is " << (char)'/a' << endl;
Firstly, the "/a" is a string, and not a single char.
You cannot use char comparison on strings.
You might wish to avail yourself of the string class and
perform the proper comparisons that way, or use the strcmp()
function in the standard STRING.H.
BW> while (--argc && **argv++) {
BW>
BW> // case '/a': isn't evaluated consistently
BW> // Best way around this?
BW> cout << "\narg entered was " << endl;
BW> switch (*(int*) *argv) {
BW> case '/a':
BW> cout << "/a" << endl;
BW> break;
BW> default:
BW> cout << *argv << " (unknown)" << endl;
BW> break;
BW> }
BW> }
Here, you assume that the type int will require two bytes.
This may not be true. You can use a short instead of int,
and that should help, but you might really be better off to
use your string class.
// begin
if((int arg = argc) > 1)
while(arg)
{
String compare = argv[--arg]
cout << "\narg entered was " << endl;
if(compare == "/a")
{
cout << compare << endl;
}
else
cout << compare << " (unknown)" << endl;
}
// end
While the switch construct is useful in an OS and platform
where the int is guaranteed to be exactly equal to two char,
it will fail once you overcome that particular restriction.
Ambiguous instructions which rely upon any hardware or
software constants other than the standard will result in
undefined results, which may vary between platforms,
environments, and compilers.
What is a clever use of the environment when you write the
code, may become a fatal error when you recompile later in
a different environment.
> ] ERROR: Demon not responding. Open pentagram to continue.....
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)
|