Double Pointers

This is a discussion on Double Pointers within the C Programming forums, part of the General Programming Boards category; Functions seem to require double FILE pointers or argv pointers, because a pointer is being passed from main to the ...

  1. #1
    Unregistered
    Guest

    Double Pointers

    Functions seem to require double FILE pointers or argv pointers, because a pointer is being passed from main to the function. Is this correct?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    ...ehhh... that depends on the function.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Unregistered
    Guest
    I'll try to be clearer. If you pass a pointer from main to a function, applying the & and *, you'd end up with no star in main and two stars in the function. Is this correct?

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    For FILE pointers, only if you open the file in the function. Otherwise a single pointer is fine.

    So two alternatives are
    1. open the file in main().

    2. Make it the return value:
    FILE *Open_File(filename)

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I don't really understand what you mean by "end up with 2 stars".
    Two stars indicates that it is a "pointer to an array of pointers".
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Unregistered
    Guest
    Hi Magos,
    As far as I know, two stars means a pointer to a pointer.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > As far as I know, two stars means a pointer to a pointer.

    Correct. It commonly is used as an array of pointers, but there is nothing specific that states "This is an array of pointers." Consider the following:

    Code:
    #include <stdio.h>
    int main ( void )
    {
        int variable = 5;
    
        int *ptr = &variable;
        int **ptrptr =&ptr;
    
        return printf( "%d %d %d", variable, *ptr, **ptrptr );
    }
    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Hi.

    char **ptr will access an array such as: char strings[100][80];

    So that ptr[6] is the same as strings[6]...

  9. #9
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >Functions seem to require double FILE pointers or argv pointers,
    >because a pointer is being passed from main to the function. Is
    >this correct?

    Depends on the function. If you change the pointer, then it is required.

    Code:
    int openfile (FILE **file)
    {
        if ((*file = fopen ("file.txt", "r")) == NULL)
            return FILE_NOT_OPENED;
        return FILE_OPENED;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. calculations with pointers
    By mackieinva in forum C Programming
    Replies: 2
    Last Post: 09-17-2007, 01:46 PM
  4. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  5. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 05:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21