Thread: char **environ

  1. #1
    Dragon Rider jas_atwal's Avatar
    Join Date
    Nov 2007
    Location
    India
    Posts
    54

    char **environ

    Below is the general syntax for environ. Is char **environ a pointor to a pointor?? I am sure it means something else... please explain..

    Code:
    #include <stdlib.h>
    extern char **environ;

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Nope, that's exactly what it is. A pointer to a pointer to a char.
    Although it is interpreted as a pointer to an array of pointers, each of which points to a C-style string.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Yes it is.

    Use it like you would the char **argv that main() receives.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by jas_atwal View Post
    Below is the general syntax for environ. Is char **environ a pointor to a pointor?? I am sure it means something else... please explain..

    Code:
    #include <stdlib.h>
    extern char **environ;
    It is a pointer to an array of char pointers. In other words, an array of strings where environ[0] is the first, environ[1] is the second, etc. It is exactly like argv but lists the environment variables instead of the command line arguments.

    I would suggest against accessing it directly. You should go through getenv() instead.

  5. #5
    Dragon Rider jas_atwal's Avatar
    Join Date
    Nov 2007
    Location
    India
    Posts
    54
    Thank you all for your replies!! I really appreciate

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  3. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM
  4. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM