Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to tell when you've reached the end of a C array? (specifically argv)

Tags:

c

argv

argc

been asked a question on this, basically coming up with argc...without actually having argc

if your given argv, which as I understand essentially a array of pointers to the relevant char arrays of each inputted argument,

how would I actually go about counting the number of pointers in argv?

like image 632
SGE Avatar asked Dec 29 '25 16:12

SGE


1 Answers

The C standard specifies:

argv[argc] shall be a null pointer.

So you can always detect the end by testing for 0.

like image 188
Jens Gustedt Avatar answered Dec 31 '25 08:12

Jens Gustedt