Thread: file pointer

  1. #1

    file pointer

    O.K. to use a file we first need to open it (make a connection in the form of a stream) this is acheived with fopen which returns a pointer to that file we then assign this returned pointer to a file pointer like so.
    FILE *file_ptr;


    so fopen returns a pointer which in turn is assigned to our pointer therefore is this a pointer to a pointer if so how come we don't need multiple indirection when declaring our file pointer like so FILE **file_ptr;.

    thaks for pointing me in the right direction.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    If you had 2 integer's (int a and int b) to copy the contents from one integer to another you'd do -

    a = b;

    If you have two pointers(int* a and int* b) to copy the contents from one to the other you'd do -

    a = b;

    If this was a pointer to a pointer then the statement would look like -

    a = &b;

    which wouldn't work because 'a' has been delcared to store the address of an integer, not a pointer.

    As fopen() doesn't return the address of a FILE pointer, but the FILE pointer itself then the first case is the one that is carried out.

  3. #3
    I think fopen returns the address of the file "structure." The value of the address is then assigned to your file pointer, so it is not a pointer to a pointer. It simply contains the address of the file.

  4. #4
    Former Member
    Join Date
    Oct 2001
    it returns a pointer, if it stores it into a pointer, no problem!


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM