Assume I have char **argv. How do I determine its size?
I have a string – an example would be: sleep 30 & that is held in argv. I would like to be able to access the last array in *argv. In this case, the last array contains &. How can I access it? strlen(argv) doesn’t seem to work properly. sizeof() obviously wouldn’t work properly because **argv is a pointer.
Note: I am not talking about **argv as an argument in main(), therefore, I do not have argc or any other indicator of how long the string is.
EDIT: Edited to work with a custom array of strings. A
NULLpointer indicates the end of the array. Although this declares an array of 4 strings, this method could be used with a dynamically sized array.For this to work for you, you would have to edit your program to explicitly include an extra
NULLstring in yourchar**when you build it. Without that indicator, the address after the last string wouldn’t necessarily beNULL, so you could include garbage in the count or cause a segmentation fault.