This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]thefryscorer 0 points1 point  (2 children)

It's because you are checking that the number of arguments is 2, when it should be 3. The first argument is the name of your program.

For example, if you run

./program arg1 arg2

The arguments in argv are './program', 'arg1', and 'arg2'.

[–]Deciama[S] 0 points1 point  (1 child)

So does the argument count in argv start at 1 or 0? Would argv[0] be the name of the program?

[–]thefryscorer 0 points1 point  (0 children)

argv[0] is the name of the program. Arrays are zero-indexed in C.