can someone show me how to parse commands passed through main. also how do i test it ? do run the command line in windows then the command along with the exe name?
maybe not so easy. its saying there is commands even when there isnt any. is there a default command also sent to main. everything seems like its one off. its also not recognizing string literals.
this doesnt work to well. at all. if i play with some options in the command prompt it does seem to pause to some commands but nothing happens. here is the code.
yes. still wasnt able to get any commands working. any at all. can anyone provide a working sample of a parsed main with options. just something with a cout << printout you choosed option x.
thank flipe i see a few different things going on that was messing everything up. i thought you were suppose to pass the number of arguments along with the arguments themselves in the command line. this screws up what i wrote up above in a major way. thanks i can work on it from here.
your example worked with just echoing but when i try and actually parse it the command is there but the parsing isnt happening. like below.
1 2 3 4 5 6 7
if (argv[1] == "compress")
std::cout << "compressing with default option";
else
{
std::cout << argv[1]; // shows up as compress then why didnt the first if fire
return 1;
}
argv in the else is called and shows up as compress then why didnt the compress in the first half of the if statement fire.
argv[1] is a character pointer. It has a value which is a numerical address; thus, you are testing a numerical address (i.e. a number) for equality to a string literal ("compress"). They are not going to be equal.
I suggest you use a comparison function, like strcmp.
ok that was the problem thanks guys. i learned tons with this exercise as aggravating as it was.
in the command line
typing main = program must require at least one argument
typing main compress = compressing with default option
typing main compress 1 = compressing with option 1
typing main compress 2 = compressing with option 2