Wow, Looks like you are angry at me.
Not really, you just make your post worth less than with correct syntax already. You could have expected posts that tell you that, rather than pointing out the real mistakes.
L0DER wrote:First of all, what was wrong with the syntax, please post the incorrect code with the correct way that it should be done.
Mostly talking about wrong comments.
Two forward slashes // begin a comment, not two backslashes \\. Those would just result in compiler errors. Besides, you misspelt argv once (agrv).
L0DER wrote:Second why argv should be checked for value which greater then two, shouldn't it be checking for existences of
array ( argv )?
argv is an array, but since it is C(++), you do not know its length. argc tells you the length of it.
Ever tried the following?
- Code: Select all
myArray = 42;
If it compiles, it will crash with an access violation. myArray can have 10 entries, but you try to access the 23rd.
Same thing (might) happens with argv. Just because it didnt crash doesnt mean it is the right way to go. Use argc instead.
L0DER wrote:What does strcmp does. Its compering between two strings, right?
As the name says, string compare. Check the Manpage
L0DER wrote:So why it cannot be done with an if statement ?
Not saying it cant be done with if, just not the way you tried.
Your code looked very PHP'ish, you wont get errors there if you try $myArray - on the contrary, it is created there. sizeof($myArray) will be either 11 if you made a hash, or 23 if you have an ordinary array.
In C/++ however, the size 10 is coded into you program - going off those limits will most certainly break.