The Length of envp in C
In the proccess of learning C, I'm trying to write a program that accepts one of your environment variable as inpu开发者_如何学运维t, and outputs its value.
The question is, is there any way to know the length of envp? I mean, how many envp is there? I'm aware that it is a char** - an array of string. And finding the size of array in C is problematic already. What can I do to know the size of envp?
Please just provide direction, not the concrete answer (or code).
It's terminated by a NULL pointer. You have to count it if you want to know the length.
the value of argv[argc] == NULL
that should give you a clue.
You should look into getenv()
. It's more portable than manipulating envp, because environments like plan9 implement the environment differently, while preserving the behavior of this function.
精彩评论