开发者

The Length of envp in C

开发者 https://www.devze.com 2023-03-26 23:47 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消